Skip to content

Exception while using module scoped fixture (ok in 2.7.3 and broken in 2.8.x) #1100

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
skirpichev opened this issue Oct 2, 2015 · 6 comments · Fixed by #1102
Closed

Exception while using module scoped fixture (ok in 2.7.3 and broken in 2.8.x) #1100

skirpichev opened this issue Oct 2, 2015 · 6 comments · Fixed by #1102

Comments

@skirpichev
Copy link

Now with my old conftest.py doesn't work. I see such tracebacks (looks similar to #943):

________________________________________________________________________ ERROR collecting sympy/abc.py _________________________________________________________________________
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/runner.py:149: in __init__
    self.result = func()
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/main.py:437: in _memocollect
    return self._memoizedcall('_collected', lambda: list(self.collect()))
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/main.py:317: in _memoizedcall
    res = function()
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/main.py:437: in <lambda>
    return self._memoizedcall('_collected', lambda: list(self.collect()))
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/doctest.py:165: in collect
    fixture_request = _setup_fixtures(self)
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/doctest.py:190: in _setup_fixtures
    fixture_request._fillfixtures()
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/python.py:1514: in _fillfixtures
    item.funcargs[argname] = self.getfuncargvalue(argname)
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/python.py:1557: in getfuncargvalue
    return self._get_active_fixturedef(argname).cached_result[0]
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/python.py:1574: in _get_active_fixturedef
    result = self._getfuncargvalue(fixturedef)
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/python.py:1624: in _getfuncargvalue
    subrequest.node)
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/python.py:1412: in node
    return self._getscopeitem(self.scope)
../../.virtualenvs/pytest-new/local/lib/python2.7/site-packages/_pytest/python.py:1658: in _getscopeitem
    assert node
E   assert None

Removing module-scoped fixtures obviously "helps".

Build logs from Travis: good and bad.

@nicoddemus
Copy link
Member

Hi @skirpichev, thanks for the report!

In case others want to take a stab at this, here's a reproducible example:

conftest.py

import pytest

@pytest.fixture(autouse=True, scope='module')
def check_disabled(request):
    assert request.module is not None

test_bug.py

def test_foo():
    """
    >>> 1 + 2
    3
    """
    pass    

Execute with:

py.test --doctest-modules
  • Moving fixture to test_bug.py no longer causes the error;
  • py.test without --doctest-modules also doesn't cause the error;

@nicoddemus
Copy link
Member

Hmmm I found a fix, but then ran into #1057 when trying to execute your test suite with my fix in place. I will need a little more time to fix this and #1057 as well.

@skirpichev
Copy link
Author

BTW, this looks like a regression. Can you include fix in the next stable point release (of course, if the fix will be available)?

skirpichev added a commit to diofant/diofant that referenced this issue Oct 2, 2015
@The-Compiler
Copy link
Member

I'll probably be the one releasing 2.8.2 at the beginning of next week - so if it's in until then, sure!

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 @skirpichev, 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

@skirpichev
Copy link
Author

On Sat, Oct 03, 2015 at 12:12:46PM -0700, Bruno Oliveira wrote:

Hi [1]@skirpichev, I just opened a PR which fix this. Could you please
confirm that it fixes your test suite?

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

Yep. Good logs from Travis:
https://travis-ci.org/skirpichev/omg/builds/83483278

Thank you for fix.

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