Skip to content

Pytest fail when autouse fixture is applied and --doctest-modules is set #1057

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

Closed
vitalk opened this issue Sep 23, 2015 · 10 comments · Fixed by #1102
Closed

Pytest fail when autouse fixture is applied and --doctest-modules is set #1057

vitalk opened this issue Sep 23, 2015 · 10 comments · Fixed by #1102
Labels
type: bug problem that needs to be addressed

Comments

@vitalk
Copy link

vitalk commented Sep 23, 2015

When --doctest-modules option is set but module has no doctests available, then pytest raises AssertionError. This issue occurs only if autouse fixture is applied.

# test_doctest_module.py

def test_a():
    """
    >>> assert 2 + 2 == 4
    """
    assert 2 + 2 == 4
# test_no_doctest_module.py

def test_a():
    assert 2 + 2 == 4
# conftest.py
import pytest


@pytest.fixture(autouse=True)
def __autoused_fixture(request):
    pass
$ py.test test_doctest_module.py --doctest-modules
================================== test session starts ==================================
platform darwin -- Python 2.7.9, pytest-2.8.0, py-1.4.30, pluggy-0.3.1
rootdir: /Users/vital/.virtualenvs/tmp-83f75479bea7798, inifile:
collected 2 items

test_doctest_module.py ..
$ py.test test_no_doctest_module.py --doctest-modules
================================== test session starts ==================================
platform darwin -- Python 2.7.9, pytest-2.8.0, py-1.4.30, pluggy-0.3.1
rootdir: /Users/vital/.virtualenvs/tmp-83f75479bea7798, inifile:
collected 1 items

test_no_doctest_module.py .ETraceback (most recent call last):
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/bin/py.test", line 11, in <module>
    sys.exit(main())
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/config.py", line 48, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/main.py", line 115, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/main.py", line 110, in wrap_session
    exitstatus=session.exitstatus)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/terminal.py", line 361, in pytest_sessionfinish
    outcome.get_result()
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    _reraise(*ex)  # noqa
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
    self.result = func()
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/runner.py", line 55, in pytest_sessionfinish
    session._setupstate.teardown_all()
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/runner.py", line 375, in teardown_all
    self._pop_and_teardown()
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/runner.py", line 348, in _pop_and_teardown
    self._teardown_with_finalization(colitem)
  File "/Users/vital/.virtualenvs/tmp-83f75479bea7798/lib/python2.7/site-packages/_pytest/runner.py", line 371, in _teardown_with_finalization
    or isinstance(colitem, tuple)
_pytest.assertion.reinterpret.AssertionError: assert (<DoctestModule 'test_no_doctest_module.py'> is None or <DoctestModule 'test_no_doctest_module.py'> in [<Session 'tmp-83f75479bea7798'>] or isinstance(<DoctestModule 'test_no_doctest_module.py'>, tuple))
 +  where [<Session 'tmp-83f75479bea7798'>] = [<Session 'tmp-83f75479bea7798'>]
 +    where [<Session 'tmp-83f75479bea7798'>] = <_pytest.runner.SetupState object at 0x10e5be7d0>.stack
$ echo > conftest.py
$ py.test test_no_doctest_module.py --doctest-modules
================================== test session starts ==================================
platform darwin -- Python 2.7.9, pytest-2.8.0, py-1.4.30, pluggy-0.3.1
rootdir: /Users/vital/.virtualenvs/tmp-83f75479bea7798, inifile:
collected 1 items

test_no_doctest_module.py .

=============================== 1 passed in 0.03 seconds ================================```
@ionelmc ionelmc added the type: bug problem that needs to be addressed label Sep 30, 2015
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Oct 2, 2015
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Oct 3, 2015
The main problem was that previously DoctestModule was setting
up its fixtures during collection, instead of letting
each DoctestItem make its own fixture setup

Fix pytest-dev#1100
Fix pytest-dev#1057
@nicoddemus
Copy link
Member

Hi @vitalk, I just opened a PR which fixes this. Could you please confirm that it fixes your test suite?

pip install git+https://github.com/nicoddemus/pytest@doctest-fixtures-fix

@vitalk
Copy link
Author

vitalk commented Oct 5, 2015

Works like a charm! Thank you.

@bukzor
Copy link

bukzor commented Oct 7, 2015

We're having this issue as well.

Please to merge and release.

@nicoddemus
Copy link
Member

@bukzor could you please test the PR branch as well?

@bukzor
Copy link

bukzor commented Oct 7, 2015

yep, it's fixed on that branch

@nicoddemus
Copy link
Member

Thanks! 😄

@bukzor
Copy link

bukzor commented Oct 7, 2015

Please to merge and release.

@ionelmc
Copy link
Member

ionelmc commented Oct 16, 2015

Did this get released yet?

@The-Compiler
Copy link
Member

No - it didn't make it into 2.8.2 and there's no 2.8.3 yet. But AFAIK @RonnyPfannschmidt plans to release 2.8.3 soon.

@twexler
Copy link

twexler commented Nov 9, 2015

Any progress on a 2.8.3 release? This issue is definitely still there.

ulif added a commit to ulif/diceware that referenced this issue Nov 14, 2015
As we introduced an py.test autouse fixture, we cannot currently also
run doctest-modules due to a bug in py.test (2.8.1, 2.8.2):

   pytest-dev/pytest#1057

Looks like a fix is planned for 2.8.3 release. Until then we have to
disable doctests in modules.
john-kurkowski added a commit to john-kurkowski/tldextract that referenced this issue Nov 16, 2015
…odules pytest-dev/pytest#1057

That means no more testpaths option. Leverage .gitignore instead. Manually exclude setup.py and tldextract_app folder.
john-kurkowski added a commit to john-kurkowski/tldextract that referenced this issue Nov 16, 2015
…odules pytest-dev/pytest#1057

That means no more testpaths option. Leverage .gitignore instead. Manually exclude setup.py and tldextract_app folder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants