question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deleted working directory in pytest-cov 2.6.0+

See original GitHub issue

For pytest-cov>=2.6, the following error results at the end of execution:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/_pytest/main.py", line 213, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/_pytest/main.py", line 257, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/pytest_cov/plugin.py", line 229, in pytest_runtestloop
INTERNALERROR>     self.cov_controller.finish()
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/pytest_cov/engine.py", line 171, in finish
INTERNALERROR>     self.cov.stop()
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/coverage/control.py", line 675, in load
INTERNALERROR>     self._init()
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/coverage/control.py", line 223, in _init
INTERNALERROR>     set_relative_directory()
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/coverage/files.py", line 28, in set_relative_directory
INTERNALERROR>     RELATIVE_DIR = os.path.normcase(abs_file(os.curdir) + os.sep)
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/site-packages/coverage/files.py", line 163, in abs_file
INTERNALERROR>     path = os.path.realpath(path)
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/posixpath.py", line 389, in realpath
INTERNALERROR>     return abspath(path)
INTERNALERROR>   File "/usr/local/miniconda/lib/python3.7/posixpath.py", line 376, in abspath
INTERNALERROR>     cwd = os.getcwd()
INTERNALERROR> FileNotFoundError: [Errno 2] No such file or directory

This appears to indicate that somewhere we change directories, then that directory gets deleted, and then os.getcwd() gets called via coverage.coverage(...).stop() before any chdir to an existing directory.

Downgrading to 2.5.1 resolves the problem. For reference, our call looks like:

pytest --junit-xml=/tmp/pytest.xml \
         --cov niworkflows --cov-report xml:/tmp/unittests.xml \
         --ignore=/src/niworkflows/niworkflows/tests/ \
         --ignore=/src/niworkflows/niworkflows/interfaces/ants.py \
         /src/niworkflows/niworkflows

Related: nedbat/coveragepy#750

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
asottilecommented, Aug 21, 2019

It’s arguably not a bug for a test to change the working directory

Consider this which I consider well formed:

import pytest


class Test:
    @pytest.fixture(scope='class', autouse=True)
    def in_tmpdir(self, tmpdir_factory):
        d = tmpdir_factory.mktemp('d')
        with d.as_cwd():
            yield d

    def test(self): ...

pytest-cov should be keeping absolute paths on construction and using those throughout

1reaction
effigiescommented, Aug 19, 2019

Took some time but: 6b1e878f3654d3758bd7f3fefcc90b0b828d158e

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Deleted working directory in pytest-cov 2.6.0+ -
For pytest-cov>=2.6 , the following error results at the end of execution: INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File ...
Read more >
pytest-cov - Read the Docs
This plugin produces coverage reports. Compared to just using coverage run this plugin does some extras: • Subprocess support: you can fork ...
Read more >
Release 2.6.0 - Pytest-Cov
path (CWD will be in it, unlike when running pytest). ... The data file is erased at the beginning of testing to ensure...
Read more >
pytest-cov - PyPI
Pytest plugin for measuring coverage.
Read more >
How to debug py.test in PyCharm when coverage is enabled
5, pytest-cache==1.0, pytest-cov==2.2.0, pytest-pep8==1.0.6, pytest-xdist==1.13.1, python-coveralls==2.6.0. (thanks for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found