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

AttributeError raised if --cov enabled twice #151

Closed
jayvdb opened this Issue Feb 23, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@jayvdb

jayvdb commented Feb 23, 2017

If --cov is enabled twice, without specifying paths each time, the following backtrace occurs.

Traceback (most recent call last):
  File "/usr/lib64/python3.5/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.5/site-packages/pytest.py", line 17, in <module>
    raise SystemExit(pytest.main())
  File "/usr/lib/python3.5/site-packages/_pytest/config.py", line 47, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python3.5/site-packages/_pytest/config.py", line 156, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/usr/lib/python3.5/site-packages/_pytest/helpconfig.py", line 32, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
    self.result = func()
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/usr/lib/python3.5/site-packages/_pytest/config.py", line 923, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python3.5/site-packages/_pytest/config.py", line 1080, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/lib/python3.5/site-packages/_pytest/config.py", line 1051, in _preparse
    args=args, parser=self._parser)
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 254, in _wrapped_call
    return call_outcome.get_result()
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
    self.result = func()
  File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/usr/lib/python3.5/site-packages/pytest_cov/plugin.py", line 95, in pytest_load_initial_conftests
    plugin = CovPlugin(ns, early_config.pluginmanager)
  File "/usr/lib/python3.5/site-packages/pytest_cov/plugin.py", line 150, in __init__
    self.start(engine.Central)
  File "/usr/lib/python3.5/site-packages/pytest_cov/plugin.py", line 171, in start
    self.cov_controller.start()
  File "/usr/lib/python3.5/site-packages/pytest_cov/engine.py", line 141, in start
    self.cov.erase()
  File "/usr/lib/python3.5/site-packages/coverage/control.py", line 727, in erase
    self._init()
  File "/usr/lib/python3.5/site-packages/coverage/control.py", line 246, in _init
    self.source.append(files.canonical_filename(src))
  File "/usr/lib/python3.5/site-packages/coverage/files.py", line 61, in canonical_filename
    if not os.path.isabs(filename):
  File "/usr/lib64/python3.5/posixpath.py", line 64, in isabs
    return s.startswith(sep)
AttributeError: 'bool' object has no attribute 'startswith'

I encountered this after adding the following to setup.cfg, which also using --cov on the command line.

[tool:pytest]
addopts =  --cov

The problem is the rather simple handling of multiple --cov at https://github.com/pytest-dev/pytest-cov/blob/master/src/pytest_cov/plugin.py#L87

@ionelmc

This comment has been minimized.

Member

ionelmc commented Feb 23, 2017

How can/should I run your coala project locally?

@jayvdb

This comment has been minimized.

jayvdb commented Feb 24, 2017

To reproduce the problem:

git clone https://github.com/coala/coala/
cd coala
python3 -m pytest --cov

To see the workaround, remove --cov (it is still enabled in setup.cfg)

python3 -m pytest

ionelmc added a commit that referenced this issue Mar 15, 2017

@ionelmc ionelmc closed this in 583a9c6 Mar 15, 2017

@ionelmc

This comment has been minimized.

Member

ionelmc commented Mar 15, 2017

Now fixed, but with a twist: if you use both --cov and --cov=foo then filters will be completely disabled (same as having only --foo). With this behavior you can put in pytest.ini something like addopts=--cov=foo, and add --cov on command line to enable coverage for everything.

jsonn pushed a commit to jsonn/pkgsrc that referenced this issue May 17, 2017

wiz
Updated py-test-cov to 2.5.1.
2.5.1 (2017-05-11)
------------------

* Fixed xdist breakage (regression in ``2.5.0``).
  Fixes `#157 <https://github.com/pytest-dev/pytest-cov/issues/157>`_.
* Allow setting custom ``data_file`` name in ``.coveragerc``.
  Fixes `#145 <https://github.com/pytest-dev/pytest-cov/issues/145>`_.
  Contributed by Jannis Leidel & Ionel Cristian Mărieș in
  `#156 <https://github.com/pytest-dev/pytest-cov/pull/156>`_.

2.5.0 (2017-05-09)
------------------

* Always show a summary when ``--cov-fail-under`` is used. Contributed by Francis Niu in `PR#141
  <https://github.com/pytest-dev/pytest-cov/pull/141>`_.
* Added ``--cov-branch`` option. Fixes `#85 <https://github.com/pytest-dev/pytest-cov/issues/85>`_.
* Improve exception handling in subprocess setup. Fixes `#144 <https://github.com/pytest-dev/pytest-cov/issues/144>`_.
* Fixed handling when ``--cov`` is used multiple times. Fixes `#151 <https://github.com/pytest-dev/pytest-cov/issues/151>`_.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment