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 import dbhash which imports bsddb. If bsddb is not present on the machine, this fails with an ImportError, which anydbm catches and silences.
When running pytest, importing a module is overridden by load_module in _pytest/assertion/rewrite.py
When the import of dbhash fails, it tries to del sys.modules['dbhash'] but this throws a KeyError since 'dbhash' is not present in sys.modules
anydbm fails to catch the KeyError since it is expecting ImportError
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
importanydbmdeftest_run():
assertTrue
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'
When trying to import the
anydbm
module from within pytest on a machine that does not havebsddb
installed, the import will fail. This appears to be becauseanydbm
tries to importdbhash
which importsbsddb
. Ifbsddb
is not present on the machine, this fails with anImportError
, whichanydbm
catches and silences.pytest
, importing a module is overridden byload_module
in _pytest/assertion/rewrite.pydbhash
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 exampleThis error occurs:
The text was updated successfully, but these errors were encountered: