[Pytest-commit] Issue #503: Session fixtures invoked (hpk42/pytest)

Andreas Pelme issues-reply at bitbucket.org
Sat Apr 12 19:04:00 CEST 2014


New issue 503: Session fixtures invoked
https://bitbucket.org/hpk42/pytest/issue/503/session-fixtures-invoked

Andreas Pelme:

Since https://bitbucket.org/hpk42/pytest-xdist/commits/05aa4f48306c905ae4d183a4b337f63cc4490466 session scoped fixtures runs multiple times.

To trace this, I have added this code to the problematic fixture:
```

class Count(object):
    counter = 0
counter = Count()

@pytest.fixture(scope='session')
def _django_db_setup(request, _django_runner, _django_cursor_wrapper):
    """Session-wide database setup, internal to pytest-django"""
    counter.counter += 1
    if counter.counter >= 2:
        print '_django_db_setup called %d times!' % counter.counter
        assert 0

    # ... no other changes

```

This is what happends:
```
$ py.test functional_tests/test_pdf_generation.py --capture=fd -v -n1
======================================================== test session starts ========================================================
platform darwin -- Python 2.7.5 -- py-1.4.21.dev1 -- pytest-2.6.0.dev1
plugins: django, xdist, cache, instafail
gw0 [3]
scheduling tests via LoadScheduling
.E
_________________________________________ ERROR at setup of test_kontrolluppgift_pdf_staff __________________________________________
[gw0] darwin -- Python 2.7.5 /Users/andreas/code/personalkollen/venv-2.7/bin/python
../pytest_django/pytest_django/plugin.py:177: in _django_db_marker
>               request.getfuncargvalue('db')
../pytest/_pytest/python.py:1319: in getfuncargvalue
>       return self._get_active_fixturedef(argname).cached_result[0]
../pytest/_pytest/python.py:1333: in _get_active_fixturedef
>           result = self._getfuncargvalue(fixturedef)
../pytest/_pytest/python.py:1385: in _getfuncargvalue
>           val = fixturedef.execute(request=subrequest)
../pytest/_pytest/python.py:1802: in execute
>           fixturedef = request._get_active_fixturedef(argname)
../pytest/_pytest/python.py:1333: in _get_active_fixturedef
>           result = self._getfuncargvalue(fixturedef)
../pytest/_pytest/python.py:1385: in _getfuncargvalue
>           val = fixturedef.execute(request=subrequest)
../pytest/_pytest/python.py:1835: in execute
>                                      self.yieldctx)
../pytest/_pytest/python.py:1761: in call_fixture_func
>           res = fixturefunc(**kwargs)
../pytest_django/pytest_django/fixtures.py:32: in _django_db_setup
>           assert 0
E           assert 0
------------------------------------------------------- Captured stdout setup -------------------------------------------------------
_django_db_setup called 2 times!
E
_________________________________________ ERROR at setup of test_kontrolluppgift_pdf_manual _________________________________________
[gw0] darwin -- Python 2.7.5 /Users/andreas/code/personalkollen/venv-2.7/bin/python
../pytest_django/pytest_django/plugin.py:177: in _django_db_marker
>               request.getfuncargvalue('db')
../pytest/_pytest/python.py:1319: in getfuncargvalue
>       return self._get_active_fixturedef(argname).cached_result[0]
../pytest/_pytest/python.py:1333: in _get_active_fixturedef
>           result = self._getfuncargvalue(fixturedef)
../pytest/_pytest/python.py:1385: in _getfuncargvalue
>           val = fixturedef.execute(request=subrequest)
../pytest/_pytest/python.py:1802: in execute
>           fixturedef = request._get_active_fixturedef(argname)
../pytest/_pytest/python.py:1333: in _get_active_fixturedef
>           result = self._getfuncargvalue(fixturedef)
../pytest/_pytest/python.py:1385: in _getfuncargvalue
>           val = fixturedef.execute(request=subrequest)
../pytest/_pytest/python.py:1835: in execute
>                                      self.yieldctx)
../pytest/_pytest/python.py:1761: in call_fixture_func
>           res = fixturefunc(**kwargs)
../pytest_django/pytest_django/fixtures.py:32: in _django_db_setup
>           assert 0
E           assert 0
------------------------------------------------------- Captured stdout setup -------------------------------------------------------
_django_db_setup called 3 times!

================================================= 1 passed, 2 error in 1.78 seconds =================================================
```

The same test works fine without xdist:
```
$ py.test functional_tests/test_pdf_generation.py --capture=fd -v
======================================================== test session starts ========================================================
platform darwin -- Python 2.7.5 -- py-1.4.21.dev1 -- pytest-2.6.0.dev1
plugins: django, xdist, cache, instafail
collected 3 items

functional_tests/test_pdf_generation.py ...

===================================================== 3 passed in 2.09 seconds ======================================================
```

This also happends with -n2, -n3 etc. It happens with pytest-xdist from revision 169 to latest tip, and pytest 2.5.2 to latest tip.




More information about the pytest-commit mailing list