Skip to content

AttributeError raised if --cov enabled twice #151

Closed

Description

@jayvdb

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

Activity

  1. ionelmc commented on Feb 23, 2017

    @ionelmc
    Member

    How can/should I run your coala project locally?

  2. jayvdb commented on Feb 24, 2017

    @jayvdb
    Author

    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
    
  3. added a commit that references this issue on Mar 15, 2017
    71e8f26
  4. ionelmc commented on Mar 15, 2017

    @ionelmc
    Member

    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.

  5. added a commit that references this issue on May 17, 2017
  6. added a commit that references this issue on Feb 15, 2020
  7. added 3 commits that reference this issue on May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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