[Pytest-commit] commit/pytest: 3 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Mar 28 09:11:03 CET 2014


3 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/250c3345c9fe/
Changeset:   250c3345c9fe
Branch:      sys_meta_path_remove_hook_only_if_present
User:        Marc Abramowitz
Date:        2014-03-28 08:33:12
Summary:     Only try to remove hook from sys.meta_path if it's present

Prevent error on exit if some code messes with sys.meta_path and removes the
assertionrewrite hook (CaptureMock seems to do this):

      File "/Users/marca/dev/hg-repos/pytest/_pytest/assertion/__init__.py", line 64, in pytest_unconfigure
        sys.meta_path.remove(hook)
    ValueError: list.remove(x): x not in list
Affected #:  2 files

diff -r 5ae1d4e50c635e3512be6cc8c16314251328d252 -r 250c3345c9fee00ba5db3c443e0e596fd3bdf870 _pytest/assertion/__init__.py
--- a/_pytest/assertion/__init__.py
+++ b/_pytest/assertion/__init__.py
@@ -60,7 +60,7 @@
 
 def pytest_unconfigure(config):
     hook = config._assertstate.hook
-    if hook is not None:
+    if hook is not None and hook in sys.meta_path:
         sys.meta_path.remove(hook)
 
 def pytest_collection(session):

diff -r 5ae1d4e50c635e3512be6cc8c16314251328d252 -r 250c3345c9fee00ba5db3c443e0e596fd3bdf870 testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -482,6 +482,22 @@
     assert "@py_builtins" in globals()""".replace("\n", "\r\n"), "wb")
         assert testdir.runpytest().ret == 0
 
+    def test_sys_meta_path_munged(self, testdir):
+        # In some versions, if any code messed with sys.meta_path and removed
+        # the assertionrewrite import hook (one example is CaptureMock), it
+        # would cause an error on py.test exit:
+        #
+        #   File "/Users/marca/dev/hg-repos/pytest/_pytest/assertion/__init__.py", line 64, in pytest_unconfigure
+        #     sys.meta_path.remove(hook)
+        # ValueError: list.remove(x): x not in list
+        #
+        testdir.tmpdir.join("test_meta_path.py").write("""#!/usr/bin/env python
+def test_meta_path():
+    import sys
+    sys.meta_path = []
+    assert True""".replace("\n", "\r\n"), "wb")
+        assert testdir.runpytest().ret == 0
+
     def test_write_pyc(self, testdir, tmpdir, monkeypatch):
         from _pytest.assertion.rewrite import _write_pyc
         from _pytest.assertion import AssertionState


https://bitbucket.org/hpk42/pytest/commits/b156b9799705/
Changeset:   b156b9799705
Branch:      sys_meta_path_remove_hook_only_if_present
User:        Marc Abramowitz
Date:        2014-03-28 09:03:52
Summary:     test_sys_meta_path_munged: Simplify with makepyfile
Affected #:  1 file

diff -r 250c3345c9fee00ba5db3c443e0e596fd3bdf870 -r b156b9799705667c88b127453edd5dfa401302b4 testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -483,19 +483,9 @@
         assert testdir.runpytest().ret == 0
 
     def test_sys_meta_path_munged(self, testdir):
-        # In some versions, if any code messed with sys.meta_path and removed
-        # the assertionrewrite import hook (one example is CaptureMock), it
-        # would cause an error on py.test exit:
-        #
-        #   File "/Users/marca/dev/hg-repos/pytest/_pytest/assertion/__init__.py", line 64, in pytest_unconfigure
-        #     sys.meta_path.remove(hook)
-        # ValueError: list.remove(x): x not in list
-        #
-        testdir.tmpdir.join("test_meta_path.py").write("""#!/usr/bin/env python
-def test_meta_path():
-    import sys
-    sys.meta_path = []
-    assert True""".replace("\n", "\r\n"), "wb")
+        testdir.makepyfile("""
+            def test_meta_path():
+                import sys; sys.meta_path = []""")
         assert testdir.runpytest().ret == 0
 
     def test_write_pyc(self, testdir, tmpdir, monkeypatch):


https://bitbucket.org/hpk42/pytest/commits/3f7abe3da427/
Changeset:   3f7abe3da427
User:        hpk42
Date:        2014-03-28 09:10:58
Summary:     Merged in msabramo/pytest/sys_meta_path_remove_hook_only_if_present (pull request #133)

Only try to remove hook from sys.meta_path if it's present
Affected #:  2 files

diff -r 5ae1d4e50c635e3512be6cc8c16314251328d252 -r 3f7abe3da42704c757ea437f14bd8caf5b8f04c7 _pytest/assertion/__init__.py
--- a/_pytest/assertion/__init__.py
+++ b/_pytest/assertion/__init__.py
@@ -60,7 +60,7 @@
 
 def pytest_unconfigure(config):
     hook = config._assertstate.hook
-    if hook is not None:
+    if hook is not None and hook in sys.meta_path:
         sys.meta_path.remove(hook)
 
 def pytest_collection(session):

diff -r 5ae1d4e50c635e3512be6cc8c16314251328d252 -r 3f7abe3da42704c757ea437f14bd8caf5b8f04c7 testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -482,6 +482,12 @@
     assert "@py_builtins" in globals()""".replace("\n", "\r\n"), "wb")
         assert testdir.runpytest().ret == 0
 
+    def test_sys_meta_path_munged(self, testdir):
+        testdir.makepyfile("""
+            def test_meta_path():
+                import sys; sys.meta_path = []""")
+        assert testdir.runpytest().ret == 0
+
     def test_write_pyc(self, testdir, tmpdir, monkeypatch):
         from _pytest.assertion.rewrite import _write_pyc
         from _pytest.assertion import AssertionState

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list