Skip to content

Commit 423b011

Browse files
authored
Merge pull request #267 from pytest-dev/better-examples
Recreate the examples
2 parents a0d0565 + 8df575e commit 423b011

File tree

22 files changed

+343
-92
lines changed

22 files changed

+343
-92
lines changed

.travis.yml

+63-25
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,112 @@ env:
55
global:
66
- LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
77
- SEGFAULT_SIGNALS=all
8-
matrix:
9-
- TOXENV=check
10-
- TOXENV=docs
11-
matrix:
8+
stages:
9+
- lint
10+
- examples
11+
- tests
12+
jobs:
1213
include:
13-
- python: '2.7'
14+
- stage: lint
15+
env:
16+
- TOXENV=check
17+
- stage: lint
18+
env:
19+
- TOXENV=docs
20+
- stage: tests
21+
python: '2.7'
1422
env:
1523
- TOXENV=py27-t310-c45
16-
- python: '2.7'
24+
- stage: tests
25+
python: '2.7'
1726
env:
1827
- TOXENV=py27-t40-c45
19-
- python: '2.7'
28+
- stage: tests
29+
python: '2.7'
2030
env:
2131
- TOXENV=py27-t41-c45
22-
- python: '3.4'
32+
- stage: tests
33+
python: '3.4'
2334
env:
2435
- TOXENV=py34-t310-c45
25-
- python: '3.4'
36+
- stage: tests
37+
python: '3.4'
2638
env:
2739
- TOXENV=py34-t40-c45
28-
- python: '3.4'
40+
- stage: tests
41+
python: '3.4'
2942
env:
3043
- TOXENV=py34-t41-c45
31-
- python: '3.5'
44+
- stage: tests
45+
python: '3.5'
3246
env:
3347
- TOXENV=py35-t310-c45
34-
- python: '3.5'
48+
- stage: tests
49+
python: '3.5'
3550
env:
3651
- TOXENV=py35-t40-c45
37-
- python: '3.5'
52+
- stage: tests
53+
python: '3.5'
3854
env:
3955
- TOXENV=py35-t41-c45
40-
- python: '3.6'
56+
- stage: tests
57+
python: '3.6'
4158
env:
4259
- TOXENV=py36-t310-c45
43-
- python: '3.6'
60+
- stage: tests
61+
python: '3.6'
4462
env:
4563
- TOXENV=py36-t40-c45
46-
- python: '3.6'
64+
- stage: tests
65+
python: '3.6'
4766
env:
4867
- TOXENV=py36-t41-c45
49-
- python: '3.7'
68+
- stage: tests
69+
python: '3.7'
5070
env:
5171
- TOXENV=py37-t310-c45
52-
- python: '3.7'
72+
- stage: tests
73+
python: '3.7'
5374
env:
5475
- TOXENV=py37-t40-c45
55-
- python: '3.7'
76+
- stage: tests
77+
python: '3.7'
5678
env:
5779
- TOXENV=py37-t41-c45
58-
- python: 'pypy2.7-6.0'
80+
- stage: tests
81+
python: 'pypy2.7-6.0'
5982
env:
6083
- TOXENV=pypy-t310-c45
61-
- python: 'pypy2.7-6.0'
84+
- stage: tests
85+
python: 'pypy2.7-6.0'
6286
env:
6387
- TOXENV=pypy-t40-c45
64-
- python: 'pypy2.7-6.0'
88+
- stage: tests
89+
python: 'pypy2.7-6.0'
6590
env:
6691
- TOXENV=pypy-t41-c45
67-
- python: 'pypy3.5-6.0'
92+
- stage: tests
93+
python: 'pypy3.5-6.0'
6894
env:
6995
- TOXENV=pypy3-t310-c45
70-
- python: 'pypy3.5-6.0'
96+
- stage: tests
97+
python: 'pypy3.5-6.0'
7198
env:
7299
- TOXENV=pypy3-t40-c45
73-
- python: 'pypy3.5-6.0'
100+
- stage: tests
101+
python: 'pypy3.5-6.0'
74102
env:
75103
- TOXENV=pypy3-t41-c45
104+
- stage: examples
105+
python: '3.6'
106+
script: cd $TARGET; tox -v
107+
env:
108+
- TARGET=examples/src-layout
109+
- stage: examples
110+
python: '3.6'
111+
script: cd $TARGET; tox -v
112+
env:
113+
- TARGET=examples/adhoc-layout
76114
before_install:
77115
- python --version
78116
- uname -a

MANIFEST.in

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
graft docs
2-
graft example
2+
graft examples
3+
prune examples/*/.tox
4+
prune examples/*/htmlcov
5+
prune examples/adhoc-layout/*.egg-info
6+
prune examples/src-layout/src/*.egg-info
7+
38
graft src
49
graft ci
510
graft tests
@@ -19,4 +24,4 @@ include README.rst
1924

2025
include tox.ini .travis.yml appveyor.yml
2126

22-
global-exclude *.py[cod] __pycache__ *.so
27+
global-exclude *.py[cod] __pycache__ *.so .coverage

ci/templates/.travis.yml

+22-7
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,37 @@ env:
55
global:
66
- LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
77
- SEGFAULT_SIGNALS=all
8-
matrix:
9-
- TOXENV=check
10-
- TOXENV=docs
11-
matrix:
8+
stages:
9+
- lint
10+
- examples
11+
- tests
12+
jobs:
1213
include:
14+
- stage: lint
15+
env:
16+
- TOXENV=check
17+
- stage: lint
18+
env:
19+
- TOXENV=docs
1320
{%- for env in tox_environments %}{{ '' }}
21+
- stage: tests
1422
{% if env.startswith("pypy-") %}
15-
- python: 'pypy2.7-6.0'
23+
python: 'pypy2.7-6.0'
1624
{% elif env.startswith("pypy3-") %}
17-
- python: 'pypy3.5-6.0'
25+
python: 'pypy3.5-6.0'
1826
{% else %}
19-
- python: '{{ "{0[2]}.{0[3]}".format(env) }}'
27+
python: '{{ "{0[2]}.{0[3]}".format(env) }}'
2028
{% endif %}
2129
env:
2230
- TOXENV={{ env }}{% if 'cover' in env %},report,coveralls,codecov{% endif -%}
2331
{%- endfor %}{{ '' }}
32+
{%- for example in ['src', 'adhoc'] %}{{ '' }}
33+
- stage: examples
34+
python: '3.6'
35+
script: cd $TARGET; tox -v
36+
env:
37+
- TARGET=examples/{{ example }}-layout
38+
{%- endfor %}{{ '' }}
2439
before_install:
2540
- python --version
2641
- uname -a

docs/config.rst

+25-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ further control of coverage use a coverage config file.
88
For example if tests are contained within the directory tree being measured the tests may be
99
excluded if desired by using a .coveragerc file with the omit option set::
1010

11-
pytest --cov-config .coveragerc
12-
--cov=myproj
13-
myproj/tests/
11+
pytest --cov-config=.coveragerc
12+
--cov=myproj
13+
myproj/tests/
1414

1515
Where the .coveragerc file contains file globs::
1616

@@ -41,3 +41,25 @@ In practical terms this means that if you have your coverage configuration in ``
4141
that you also use ``--cov-config=tox.ini`` or ``--cov-config=setup.cfg``.
4242

4343
You might not be affected but it's unlikely that you won't ever use ``chdir`` in a test.
44+
45+
Reference
46+
=========
47+
48+
The complete list of command line options is:
49+
50+
--cov=PATH Measure coverage for filesystem path. (multi-allowed)
51+
--cov-report=type Type of report to generate: term, term-missing,
52+
annotate, html, xml (multi-allowed). term, term-
53+
missing may be followed by ":skip-covered". annotate,
54+
html and xml may be followed by ":DEST" where DEST
55+
specifies the output location. Use --cov-report= to
56+
not generate any output.
57+
--cov-config=path Config file for coverage. Default: .coveragerc
58+
--no-cov-on-fail Do not report coverage if test run fails. Default:
59+
False
60+
--no-cov Disable coverage report completely (useful for
61+
debuggers). Default: False
62+
--cov-fail-under=MIN Fail if the total coverage is less than MIN.
63+
--cov-append Do not delete coverage but append to current. Default:
64+
False
65+
--cov-branch Enable branch coverage.

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Contents:
1212
debuggers
1313
xdist
1414
subprocess-support
15+
tox
1516
plugins
1617
markers-fixtures
1718
changelog

docs/tox.rst

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
===
2+
Tox
3+
===
4+
5+
When using `tox <https://tox.readthedocs.io/>`_ you can have ultra-compact configuration - you can have all of it in
6+
``tox.ini``::
7+
8+
[tox]
9+
envlist = ...
10+
11+
[tool:pytest]
12+
...
13+
14+
[coverage:paths]
15+
...
16+
17+
[coverage:run]
18+
...
19+
20+
[coverage:report]
21+
..
22+
23+
[testenv]
24+
commands = ...
25+
26+
An usual problem users have is that pytest-cov will erase the previous coverage data by default, thus if you run tox
27+
with multiple environments you'll get incomplete coverage at the end.
28+
29+
To prevent this problem you need to use ``--cov-append``. It's still recommended to clean the previous coverage data to
30+
have consistent output. A ``tox.ini`` like this should be enough for sequential runs::
31+
32+
[tox]
33+
envlist = clean,py27,py36,...
34+
35+
[testenv]
36+
commands = pytest --cov --cov-append --cov-report=term-missing ...
37+
deps =
38+
pytest
39+
pytest-cov
40+
41+
[testenv:clean]
42+
deps = coverage
43+
skip_install = true
44+
commands = coverage erase
45+
46+
For parallel runs we need to set some dependencies and have an extra report env like so::
47+
48+
[tox]
49+
envlist = clean,py27,py36,report
50+
51+
[testenv]
52+
commands = pytest --cov --cov-append --cov-report=term-missing
53+
deps =
54+
pytest
55+
pytest-cov
56+
depends =
57+
{py27,py36}: clean
58+
report: py27,py36
59+
60+
[testenv:report]
61+
deps = coverage
62+
skip_install = true
63+
commands =
64+
coverage report
65+
coverage html
66+
67+
[testenv:clean]
68+
deps = coverage
69+
skip_install = true
70+
commands = coverage erase
71+
72+
Depending on your project layout you might need extra configuration, see the working examples at
73+
https://github.com./pytest-dev/pytest-cov/tree/master/examples for two common layouts.

example/.coveragerc

-2
This file was deleted.

example/setup.py

-7
This file was deleted.

example/tests/test_mylib.py

-7
This file was deleted.

example/tox.ini

-30
This file was deleted.

examples/README.rst

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Simple examples with ``tox.ini``
2+
================================
3+
4+
These examples provide necessary configuration to:
5+
6+
* aggregate coverage from multiple interpreters
7+
* support tox parallel mode
8+
* run tests on installed code
9+
10+
The `adhoc` layout is the old and problematic layout where you can mix up the installed code
11+
with the source code. However, these examples will provide correct configuration even for
12+
the `adhoc` layout.
13+
14+
The `src` layout configuration is less complicated, have that in mind when picking a layout
15+
for your project.

0 commit comments

Comments
 (0)