Coverage report generation incompatible with pytest `tmpdir` feature
See original GitHub issueGiven a project structure like:
myproject
├── myproject
│ └── __init__.py
├── tests
│ └── myproject
│ └── test.py
└── setup.cfg
I’m running the command in the toplevel myproject
directory:
py.test --cov=myproject --cov-report html
On stdout I can see the log output:
Coverage HTML written to dir htmlcov
However no output has been written, i.e., the myproject
directory does not contain htmlcov
(and neither of its subdirectories). Even a find / -name "*htmlcov*"
reveals nothing.
Notes:
- The output is written if I use
--cov-report html:/absolute/path/to/myproject/htmlcov
. - I get the same issue for
--cov-report xml
. - My tests
chdir
a lot – can this mess up pytest-cov?
Versions:
- pytest: 3.8.1
- pytest-cov: 2.6.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (11 by maintainers)
Top Results From Across the Web
Full pytest documentation
How to write and report assertions in tests · Asserting with the assert statement · Assertions about expected exceptions · Assertions about expected ......
Read more >pytest Documentation - Read the Docs
Execute the test function with “quiet” reporting mode: $ pytest -q ... pytest-cov: coverage reporting, compatible with distributed testing.
Read more >Release 5.3.1 unknown - Coverage.py
Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts.
Read more >Diff - refs/heads/experimental/pyarmnn^! - ml/armnn - Gitiles
+enable= + + +[REPORTS] + +# Python expression which should return a note less than ... is used to generate the Arm NN...
Read more >Changelog — Dask.distributed 2022.12.1 documentation
Work around incompatibility of crick with setuptools 65 (GH#6887) crusaderky ... Generate junit report when pytest-timeout kills pytest (GH#5832) crusaderky.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also ran into the same issue recently where I couldn’t chdir into pytest’s
tmpdir
feature without breaking how pytest-cov locates the coverage report at the end of a test suite, so I figured I would leave a comment with a quick solution to help anyone else who might have the same problems in the future. To keep the linetmpdir.chdir()
in theinitdir
fixture without adversely affecting any downstream tests or the coverage report generation, simply add a constant at the top of your test likeOLD_DIR = os.getcwd()
and then add the following to your tearDownClass (assuming you’re using the pytest fixtures within a unittest TestCase):This will cleanly revert the current working directory to the previous directory before
tmpdir
once the tests have completed so the coverage report can successfully be located after the test suite has completed.We could try to make sure we dump the report in the original cwd tho (just like we handle config paths).