-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Description
When trying to import the anydbm
module from within pytest on a machine that does not have bsddb
installed, the import will fail. This appears to be because
- Importing
anydbm
tries to importdbhash
which importsbsddb
. Ifbsddb
is not present on the machine, this fails with anImportError
, whichanydbm
catches and silences. - When running
pytest
, importing a module is overridden byload_module
in _pytest/assertion/rewrite.py - When the import of
dbhash
fails, it tries todel sys.modules['dbhash']
but this throws a KeyError since'dbhash'
is not present insys.modules
anydbm
fails to catch theKeyError
since it is expectingImportError
Observed in pytest 3.0.5 on both OS X and Ubuntu.
This can be reproduced by including import anydbm
in any test file. For example
import anydbm
def test_run():
assert True
This error occurs:
testl.py:1: in <module>
import anydbm
../.virtualenvs/test2/lib/python2.7/site-packages/_pytest/assertion/rewrite.py:216: in load_module
py.builtin.exec_(co, mod.__dict__)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/anydbm.py:45: in <module>
_mod = __import__(_name)
../.virtualenvs/test2/lib/python2.7/site-packages/_pytest/assertion/rewrite.py:218: in load_module
del sys.modules[name]
E KeyError: 'dbhash'
$ pip list
appdirs (1.4.0)
packaging (16.8)
pip (9.0.1)
py (1.4.32)
pyparsing (2.1.10)
pytest (3.0.5)
setuptools (34.2.0)
six (1.10.0)
wheel (0.30.0a0)
Metadata
Metadata
Assignees
Labels
No labels