From 58ce3a9e8c48fe557bfdc644a96df234936247e1 Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Tue, 14 Feb 2017 16:54:32 -0800 Subject: [PATCH 1/4] Safer sys.modules delete --- _pytest/assertion/rewrite.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index abf5b491f..7408c4746 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -215,7 +215,8 @@ class AssertionRewritingHook(object): 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] From 00ec30353b090f8bc5ab36b7a6738f74477df0ba Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Tue, 14 Feb 2017 17:08:42 -0800 Subject: [PATCH 2/4] Update docs as requested --- AUTHORS | 1 + CHANGELOG.rst | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/AUTHORS b/AUTHORS index b09516a1d..b49405bf7 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 f33663b2a..394c57fa4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,9 @@ 3.0.7 (unreleased) ================== +* Fix issue when trying to import the `anydbm` module. (`#2248`_). + Thanks `@pfhayes`_ for the PR. + * Fix regression, pytest now skips unittest correctly if run with ``--pdb`` (`#2137`_). Thanks to `@gst`_ for the report and `@mbyt`_ for the PR. @@ -30,6 +33,7 @@ .. _@gst: https://github.com/gst .. _@vidartf: https://github.com/vidartf +.. _#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 From 49289fed52eb99f3a3258d71e2e6ab24a850658a Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Tue, 14 Feb 2017 17:21:20 -0800 Subject: [PATCH 3/4] Fix docs --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 394c57fa4..f172be1ea 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -29,6 +29,7 @@ * +.. _@pfhayes: https://github.com/pfhayes .. _@bluetech: https://github.com/bluetech .. _@gst: https://github.com/gst .. _@vidartf: https://github.com/vidartf From 6b5566db66300f9a566efecf1d9389842dc9581a Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Tue, 14 Feb 2017 17:47:42 -0800 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f172be1ea..23ff64320 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,9 @@ 3.0.7 (unreleased) ================== -* Fix issue when trying to import the `anydbm` module. (`#2248`_). +* 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. * Fix regression, pytest now skips unittest correctly if run with ``--pdb``