pytest-dev / pytest-dev/pytest
addopts behavior with coverage flag
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
(uncertain if this is specific to py.test config, or pytest-cov, apologies if I'm putting it in the wrong place)
- Include a detailed description of the bug or suggestion
It appears that the addopts section of config file appends positional arguments to option flags following, making specifying a path of tests to include dependent on the order of the option flags.
Note: I use the --collect-only flag as an example, in my project I've got others like --duration=10, etc - I tried to use a simple reproduction approach.
-
pip listof the virtual environment you are using
coverage (4.3.1)
pip (9.0.1)
py (1.4.32)
pytest (3.0.5)
pytest-cov (2.4.0)
setuptools (32.3.0)
wheel (0.30.0a0)
- pytest and operating system versions
$ python --version
Python 2.7.13
$ py.test --version
This is pytest version 3.0.5, imported from ..../lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
pytest-cov-2.4.0 at ..../lib/python2.7/site-packages/pytest_cov/plugin.py
- Minimal example if possible
Given a setup.cfg section like:
[tool:pytest]
addopts = --collect-only --cov
And a directory tree structure like:
.
├── app
│ ├── one
│ │ └── test_sample1.py
│ └── two
│ └── test_sample2.py
└── setup.cfg
3 directories, 3 files
And test_sample?.py contains this example:
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
When running py.test app/one/
Then both test cases are collected, instead of only one.
Output:
============================= test session starts ==============================
platform darwin -- Python 2.7.13, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /Users/miketheman/tmp/pytest-repro, inifile: setup.cfg
plugins: cov-2.4.0
collected 2 items
<Module 'app/one/test_sample1.py'>
<Function 'test_answer'>
<Module 'app/two/test_sample2.py'>
<Function 'test_answer'>
---------- coverage: platform darwin, python 2.7.13-final-0 ----------
Name Stmts Miss Cover
---------------------------------------------
app/one/test_sample1.py 4 2 50%
========================= no tests ran in 0.02 seconds =========================
It appears that the path specified on the commandline is being passed to --cov
Workaround
Changing the setup.cfg to reverse the options like so:
[tool:pytest]
addopts = --cov --collect-only
Produces the correct result:
============================= test session starts ==============================
platform darwin -- Python 2.7.13, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /Users/miketheman/tmp/pytest-repro, inifile: setup.cfg
plugins: cov-2.4.0
collected 1 items
<Module 'app/one/test_sample1.py'>
<Function 'test_answer'>
---------- coverage: platform darwin, python 2.7.13-final-0 ----------
Name Stmts Miss Cover
---------------------------------------------
app/one/test_sample1.py 4 2 50%
========================= no tests ran in 0.01 seconds =========================
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior with the setup.cfg [tool:pytest] addopts examples and the app/one/ and app/two/ layout, comparing both option orders. Trace pytest's addopts and command-line argument handling alongside pytest-cov's --cov option; done means py.test app/one/ collects only the test under app/one/ in either order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100