Issues

Issue #336 resolved

pytest-2.4.0.dev7 crashes with some autouse fixtures

Andreas Pelme avatarAndreas Pelme created an issue

I just installed the latest dev version of pytest (pip install -i http://pypi.testrun.org -U pytest) and got this error:

platform darwin -- Python 2.7.2 -- pytest-2.4.0.dev7 -- /Users/andreas/.virtualenvs/pk/bin/python
plugins: cache, contextfixture, cov, django, instafail, pep8, poo, xdist

________ ERROR collecting functional_tests/something.py _____________
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/runner.py:129: in __init__
>               self.result = func()
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/main.py:380: in _memocollect
>       return self._memoizedcall('_collected', lambda: list(self.collect()))
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/main.py:293: in _memoizedcall
>           res = function()
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/main.py:380: in <lambda>
>   return self._memoizedcall('_collected', lambda: list(self.collect()))
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/unittest.py:38: in collect
>           yield TestCaseFunction(name, parent=self)
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/python.py:953: in __init__
>                                                  funcargs=not isyield)
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/python.py:1476: in getfixtureinfo
>                                                             node)
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/python.py:1531: in getfixtureclosure
>       fixturenames_closure = self._getautousenames(parentid)
../../.virtualenvs/pk/lib/python2.7/site-packages/_pytest/python.py:1510: in _getautousenames
>           if nodeid.startswith(baseid):
E           TypeError: startswith first arg must be str, unicode, or tuple, not NoneType

I have not done any extensive debugging, but this is the value of basenames when the crash occurs:

['_django_clear_outbox', '_django_cursor_wrapper', '_django_db_marker', '_django_runner', '_django_set_urlconf', '_django_setup_unittest', '_live_server_helper']

These are the names of pytest-django autouse fixtures, so this might very well be a bug in pytest-django.

I can probably try to tackle this at august 1st, but my fixture internals knowledge is very limited. :-)

This crash does not occur with pytest 2.3.5.

Comments (8)

  1. holger krekel

    I doubt you installed the latest version - it still shows pytest-2.4.dev7 but trunk has dev8 now. (UPDATE: ok, you probably didn't repaste the traceback). The line number of python.py:1510 doesn't show the line of your traceback. I'd like to have a trunk-based traceback if possible.

  2. Andreas Pelme

    I ran with dev8 too, but did not repost the traceback.

    This is the full traceback:

    $ py.test -x -vvvvv
    ===================================================== test session starts =====================================================
    platform darwin -- Python 2.7.2 -- pytest-2.4.0.dev8 -- /Users/andreas/.virtualenvs/removed/bin/python
    cachedir: /Users/andreas/code/removed/.cache
    plugins: cache, contextfixture, cov, django, instafail, pep8, poo, xdist
    _____________________________________ ERROR collecting functional_tests/removed.py _____________________________________
    ../pytest/_pytest/runner.py:129: in __init__
    >               self.result = func()
    ../pytest/_pytest/main.py:380: in _memocollect
    >       return self._memoizedcall('_collected', lambda: list(self.collect()))
    ../pytest/_pytest/main.py:293: in _memoizedcall
    >           res = function()
    ../pytest/_pytest/main.py:380: in <lambda>
    >   return self._memoizedcall('_collected', lambda: list(self.collect()))
    ../pytest/_pytest/unittest.py:38: in collect
    >           yield TestCaseFunction(name, parent=self)
    ../pytest/_pytest/python.py:953: in __init__
    >                                                  funcargs=not isyield)
    ../pytest/_pytest/python.py:1476: in getfixtureinfo
    >                                                             node)
    ../pytest/_pytest/python.py:1531: in getfixtureclosure
    >       fixturenames_closure = self._getautousenames(parentid)
    ../pytest/_pytest/python.py:1510: in _getautousenames
    >           if nodeid.startswith(baseid):
    E           TypeError: startswith first arg must be str, unicode, or tuple, not NoneType
    
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ================================================== 1 error in 13.25 seconds ===================================================
    

    I double checked the line numbers just to be sure, and this where the crash happends which matches my current checkout:

    https://bitbucket.org/hpk42/pytest/src/abfc7dc64ed4f5a50e917ac8a30863be7e2361a7/_pytest/python.py?at=default#cl-1510

  3. Floris Bruynooghe

    Fix issue 336: autouse fixtures in plugins work again

    When an autouse fixture in a plugin was encountered None was stored as nodeid where it used to be ''. This broke the lookup of autouse fixtures later on.

    This also adds another test for the normal fixture ordering which was slightly wrong: a fixture without location was always added at the front of the fixture list rather then at the end of the fixtures without location but before the fixtures with location.

    → <<cset 34084c396adc>>

  4. Andreas Pelme

    I just ran my test suite with the current hg tip - everything works. Thanks a lot for fixing this!

    Also, the new terminal reporting is very nice with the colors + summary/timing in non-verbose mode.

  5. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.