Skip to content

Commit cb738d5

Browse files
committed
Makefile help / moving examples.
1 parent 3edd8b6 commit cb738d5

File tree

25 files changed

+85
-25
lines changed

25 files changed

+85
-25
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
.PHONY: clean-pyc clean-build docs clean
22

33
help:
4+
@echo "clean Lint, test, check coverage and package"
45
@echo "clean Remove all build, test, coverage and Python artifacts"
56
@echo "clean-build Remove build artifacts"
67
@echo "clean-pyc Remove Python file artifacts"
78
@echo "clean-test Remove test and coverage artifacts"
89
@echo "lint Check style with Flake8 and Pylint"
9-
@echo "test Run tests quickly with Python 3.11"
10-
@echo "test-all Run tests on every Python version with tox"
10+
@echo "test Run quick tests and those for the example code"
11+
@echo "test-quick Run tests quickly (main code only)with Python 3.11"
12+
@echo "test-example Run tests for the example code"
13+
@echo "test-all Run tests on every Python version with tox and the example"
1114
@echo "coverage Check code coverage quickly with Python 3"
1215
@echo "dist Package"
1316

@@ -31,7 +34,7 @@ clean-test:
3134
rm -f .coverage
3235
rm -fr htmlcov/
3336

34-
all: lint test-all coverage dist readme
37+
all: lint test-all coverage dist
3538

3639
lint:
3740
tox -e lint

README.rst

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,14 @@ Upgrade to 3.0
8585
Version 3 now uses `tmp_path`_, resulting in `pathlib.Path` objects
8686
instead of `py.path`.
8787

88-
Your tests may need to be adjusted.
89-
90-
.. literalinclude:: tests/examples/example_upgradev3.py
91-
:language: python
88+
Your tests may need to be adjusted. In `examples/example_upgradev3.py` you see some possible
89+
variations.
9290

9391

9492
Usage
9593
-----
9694

97-
These examples can also be found in `tests/examples`.
95+
The full code with more details for the examples can be found in `examples/`.
9896

9997
Example 1
10098
~~~~~~~~~
@@ -105,8 +103,14 @@ large video files stored under */opt/big_files/* . You don't want your tests mod
105103
the original files, but the files are required by the tests. You can reference these
106104
data files in your test method as follows:
107105

108-
.. literalinclude:: tests/examples/example_1.py
109-
:language: python
106+
.. code-block:: python
107+
108+
# more details in `examples/example_1.py`
109+
110+
@pytest.mark.datafiles('/opt/big_files/film1.mp4')
111+
def test_fast_forward(datafiles):
112+
# ...
113+
110114
111115
Example 2
112116
~~~~~~~~~
@@ -116,17 +120,39 @@ place a directory named *test_files*. Here you have a lot of images you want to
116120
on. By using this plugin, you make sure the original files under *test_files* are not
117121
modified by every test.
118122

119-
.. literalinclude:: tests/examples/example_2.py
120-
:language: python
123+
.. code-block:: python
124+
125+
# more details in `examples/example_2.py`
126+
127+
@pytest.mark.datafiles(
128+
FIXTURE_DIR / 'img1.jpg',
129+
FIXTURE_DIR / 'img2.jpg',
130+
FIXTURE_DIR / 'img3.jpg',
131+
)
132+
def test_find_borders(datafiles):
133+
# ...
134+
121135
122136
Example 3
123137
~~~~~~~~~
124138

125139
If all (or many) of your tests rely on the same files it can be easier to
126140
define one decorator beforehand and apply it to every test like this example:
127141

128-
.. literalinclude:: tests/examples/example_3.py
129-
:language: python
142+
.. code-block:: python
143+
144+
# more details in `examples/example_3.py`
145+
146+
ALL_IMGS = pytest.mark.datafiles(
147+
FIXTURE_DIR / 'img1.jpg',
148+
FIXTURE_DIR / 'img2.jpg',
149+
FIXTURE_DIR / 'img3.jpg',
150+
)
151+
152+
@ALL_IMGS
153+
def test_something1(datafiles):
154+
# ...
155+
130156
131157
Example 4
132158
~~~~~~~~~
@@ -136,16 +162,23 @@ Imagine you have 3 directories (*dir1*, *dir2*, *dir3*) each containing the file
136162

137163
This example clarifies the options **on_duplicate** and **keep_top_dir**.
138164

139-
.. literalinclude:: tests/examples/example_4.py
140-
:language: python
141165

142166
Example 5
143167
~~~~~~~~~
144168

145169
You can also use a str paths.
146170

147-
.. literalinclude:: tests/examples/example_5.py
148-
:language: python
171+
.. code-block:: python
172+
173+
# more details in `examples/example_5.py`
174+
175+
@pytest.mark.datafiles(
176+
os.path.join(FIXTURE_DIR, 'img1.jpg'),
177+
os.path.join(FIXTURE_DIR, 'img2.jpg'),
178+
os.path.join(FIXTURE_DIR, 'img3.jpg'),
179+
)
180+
def test_str(datafiles):
181+
# ...
149182
150183
151184
Contributing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/examples/example_1.py renamed to examples/example_1.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
"""Example: Reference files anywhere """
1+
"""Example: Reference files anywhere.
2+
3+
One possible use case is when you are running tests on very big files that are
4+
not included or packaged with your tests. For example, your test files are
5+
large video files stored under */opt/big_files/* . You don't want your tests
6+
modifying the original files, but the files are required by the tests.
7+
8+
"""
29
import os
310
import pytest
411

tests/examples/example_2.py renamed to examples/example_2.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
"""Example: make a subset of the files in a dir available."""
1+
"""Example: make a subset of the files in a dir available.
2+
3+
Now for another use case: let's say in the directory where your tests are
4+
located, you place a directory named *test_files*. Here you have a lot of
5+
images you want to run tests on. By using this plugin, you make sure the
6+
original files under *test_files* are not modified by every test.
7+
8+
"""
29
from pathlib import Path
310

411
import pytest

0 commit comments

Comments
 (0)