diff --git a/AUTHORS b/AUTHORS index b09516a1dd0..b49405bf757 100644 --- a/AUTHORS +++ b/AUTHORS @@ -113,6 +113,7 @@ Nicolas Delaby Oleg Pidsadnyi Oliver Bestwalter Omar Kohl +Patrick Hayes Pieter Mulder Piotr Banaszkiewicz Punyashloka Biswal diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d309125d91a..32726274f4e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ 3.0.7 (unreleased) ================== + +* Fix issue in assertion rewriting breaking due to modules silently discarding + other modules when importing fails + Notably, importing the `anydbm` module is fixed. (`#2248`_). + Thanks `@pfhayes`_ for the PR. + * junitxml: Fix problematic case where system-out tag occured twice per testcase element in the XML report. Thanks `@kkoukiou`_ for the PR. @@ -30,12 +36,14 @@ * +.. _@pfhayes: https://github.com/pfhayes .. _@bluetech: https://github.com/bluetech .. _@gst: https://github.com/gst .. _@sirex: https://github.com/sirex .. _@vidartf: https://github.com/vidartf .. _@kkoukiou: https://github.com/KKoukiou +.. _#2248: https://github.com/pytest-dev/pytest/issues/2248 .. _#2137: https://github.com/pytest-dev/pytest/issues/2137 .. _#2160: https://github.com/pytest-dev/pytest/issues/2160 .. _#2231: https://github.com/pytest-dev/pytest/issues/2231 diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index abf5b491fe3..7408c47469f 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -215,7 +215,8 @@ def load_module(self, name): mod.__loader__ = self py.builtin.exec_(co, mod.__dict__) except: - del sys.modules[name] + if name in sys.modules: + del sys.modules[name] raise return sys.modules[name]