Skip to content

--cov fails with pytest-xdist #110

@lsglick

Description

@lsglick

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions