Skip to content

Instantly share code, notes, and snippets.

@joar
Created April 5, 2013 21:42
Show Gist options
  • Save joar/5322867 to your computer and use it in GitHub Desktop.
Save joar/5322867 to your computer and use it in GitHub Desktop.
Python pytest virtualenv gotcha

I encountered this issue:

(mediagoblin)➜  ~VIRTUAL_ENV git:(master) ✗ ./runtests.sh                                                                         belz
Using ./bin/py.test
+ CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests
+ exec ./bin/py.test ./mediagoblin/tests --boxed
/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/assertion/oldinterpret.py:3: DeprecationWarning: The compiler package is deprecated and removed in Python 3.x.
  from compiler import parse, ast, pycodegen
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/main.py", line 77, in wrap_session
INTERNALERROR>     config.pluginmanager.do_configure(config)
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/core.py", line 268, in do_configure
INTERNALERROR>     config.hook.pytest_configure(config=self._config)
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/core.py", line 422, in __call__
INTERNALERROR>     return self._docall(methods, kwargs)
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/core.py", line 433, in _docall
INTERNALERROR>     res = mc.execute()
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/core.py", line 351, in execute
INTERNALERROR>     res = method(**kwargs)
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest_xdist-1.8-py2.7.egg/xdist/plugin.py", line 60, in pytest_configure
INTERNALERROR>     __multicall__.execute()
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/core.py", line 351, in execute
INTERNALERROR>     res = method(**kwargs)
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/assertion/__init__.py", line 45, in pytest_configure
INTERNALERROR>     _load_modules(mode)
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/assertion/__init__.py", line 102, in _load_modules
INTERNALERROR>     from _pytest.assertion import reinterpret
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/assertion/reinterpret.py", line 42, in <module>
INTERNALERROR>     from _pytest.assertion.oldinterpret import interpret as reinterpret_old
INTERNALERROR>   File "/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/assertion/oldinterpret.py", line 3, in <module>
INTERNALERROR>     from compiler import parse, ast, pycodegen
INTERNALERROR>   File "/usr/lib/python2.7/compiler/__init__.py", line 29, in <module>
INTERNALERROR>     from compiler.transformer import parse, parseFile
INTERNALERROR>   File "/usr/lib/python2.7/compiler/transformer.py", line 29, in <module>
INTERNALERROR>     import parser
INTERNALERROR> ImportError: /home/joar/git/mediagoblin/lib/python2.7/lib-dynload/parser.so: undefined symbol: _PyNode_SizeOf

As you see, I have pytest installed in a virtualenv and I'm using the virtualenv's python when running the pytest.

My solution was to re-initialize my virtualenv with

virtualenv --system-site-packages .

Good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment