Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--cov fails with pytest-xdist #110

Closed
lsglick opened this issue Mar 15, 2016 · 5 comments · Fixed by #120
Closed

--cov fails with pytest-xdist #110

lsglick opened this issue Mar 15, 2016 · 5 comments · Fixed by #120

Comments

@lsglick
Copy link

lsglick commented Mar 15, 2016

Trying to specify --cov with no source directories specified fails when using pytest-xdist.

E.g. py.test --cov -n 2 (with a .coveragerc file specifying sources) will fail, while py.test --cov will succeed. Also, py.test --cov=. -n 2 will succeed.

I'm using pytest 2.9.0, pytest-cov 2.2.1, and pytest-xdist 1.14. I've run on both Mac OS and Linux.

The error message is:

  1 INTERNALERROR> Traceback (most recent call last):
  2 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/_pytest/main.py", line 92, in wrap_session
  3 INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
  4 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
  5 INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  6 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
  7 INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
  8 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
  9 INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
 10 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
 11 INTERNALERROR>     res = hook_impl.function(*args)
 12 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/pytest_cov/plugin.py", line 136, in pytest_sessionstart
 13 INTERNALERROR>     self.start(engine.DistSlave, session.config, nodeid)
 14 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/pytest_cov/plugin.py", line 123, in start
 15 INTERNALERROR>     self.cov_controller.start()
 16 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/pytest_cov/engine.py", line 245, in start
 17 INTERNALERROR>     self.cov.erase()
 18 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/coverage/control.py", line 709, in erase
 19 INTERNALERROR>     self._init()
 20 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/site-packages/coverage/control.py", line 231, in _init
 21 INTERNALERROR>     if os.path.exists(src):
 22 INTERNALERROR>   File "~/Dev/.virtualenvs/workspace/lib/python2.7/genericpath.py", line 26, in exists
 23 INTERNALERROR>     os.stat(path)
 24 INTERNALERROR> TypeError: coercing to Unicode: need string or buffer, bool found
 25 [gw0] node down: Not properly terminated

I've traced this to the following line succeeding for the centralized and master case:

    if ns.cov_source == [True]:
        ns.cov_source = None

(https://github.com/pytest-dev/pytest-cov/blob/master/src/pytest_cov/plugin.py#L48)

But not for slaves which skip the pytest_load_initial_conftests hook and only run the pytest_configure hook: https://github.com/pytest-dev/pytest-cov/blob/master/src/pytest_cov/plugin.py#L61.

One simple fix would be to move the check for [True] to CovPlugin.start() before initializing cov_controller, but I wasn't sure if you were trying to keep the argument parsing only during initialization.

@ionelmc
Copy link
Member

ionelmc commented Mar 15, 2016

Does this reproduce if you swap the argument order or move --cov at the end? Eg: py.test -n 2 --cov

@ionelmc
Copy link
Member

ionelmc commented Mar 15, 2016

To put this differently, if you add any other non-option argument (like a path to test file) then it will be assigned to --cov.

It's an old problem, but we can fix it, but only if we break some backwards compatibility. I wonder how many people stumble on this ...

@lsglick
Copy link
Author

lsglick commented Mar 15, 2016

Changing argument order, specifying a path to a specific test file, and a few other combinations all fail the same way. I can't ever get it to pass with --cov and xdist unless I make sure to check for config.option.cov_source == [True] and set it to None.

Honestly I was surprised I couldn't find any other references to this problem since it is so easy to reproduce. I guess most people specify --cov=proj or don't use xdist?

@The-Compiler
Copy link
Member

FWIW, the current --cov behaviour has tripped up some people in e.g. #pylib, including me 😉

@ionelmc
Copy link
Member

ionelmc commented Mar 15, 2016

@lsglick I misunderstood this. Indeed this is a different problem. I'm also surprised no one hit it yet. I guess no one really uses bare --cov. Will fix this, regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants