[py-svn] commit/pytest: RonnyPfannschmidt: support pytest.set_trace in collection

Bitbucket commits-noreply at bitbucket.org
Mon Aug 1 10:56:12 CEST 2011


1 new changeset in pytest:

http://bitbucket.org/hpk42/pytest/changeset/bbe034e34d7a/
changeset:   bbe034e34d7a
user:        RonnyPfannschmidt
date:        2011-08-01 10:53:37
summary:     support pytest.set_trace in collection
affected #:  2 files (647 bytes)

--- a/_pytest/pdb.py	Mon Jul 25 21:42:57 2011 -0500
+++ b/_pytest/pdb.py	Mon Aug 01 10:53:37 2011 +0200
@@ -19,11 +19,13 @@
 class pytestPDB:
     """ Pseudo PDB that defers to the real pdb. """
     item = None
+    collector = None
 
     def set_trace(self):
         """ invoke PDB set_trace debugging, dropping any IO capturing. """
         frame = sys._getframe().f_back
-        item = getattr(self, 'item', None)
+        item = self.item or self.collector
+
         if item is not None:
             capman = item.config.pluginmanager.getplugin("capturemanager")
             out, err = capman.suspendcapture()
@@ -38,6 +40,14 @@
     pytestPDB.item = item
 pytest_runtest_setup = pytest_runtest_call = pytest_runtest_teardown = pdbitem
 
+ at pytest.mark.tryfirst
+def pytest_make_collect_report(__multicall__, collector):
+    try:
+        pytestPDB.collector = collector
+        return __multicall__.execute()
+    finally:
+        pytestPDB.collector = None
+
 def pytest_runtest_makereport():
     pytestPDB.item = None
     


--- a/testing/test_pdb.py	Mon Jul 25 21:42:57 2011 -0500
+++ b/testing/test_pdb.py	Mon Aug 01 10:53:37 2011 +0200
@@ -144,6 +144,19 @@
         child.sendeof()
         child.wait()
 
+    def test_pdb_used_in_generate_tests(self, testdir):
+        p1 = testdir.makepyfile("""
+            import pytest
+            def pytest_generate_tests(metafunc):
+                pytest.set_trace()
+                x = 5
+            def test_foo(a):
+                pass
+        """)
+        child = testdir.spawn_pytest(str(p1))
+        child.expect("x = 5")
+        child.sendeof()
+        child.wait()
     def test_pdb_collection_failure_is_shown(self, testdir):
         p1 = testdir.makepyfile("""xxx """)
         result = testdir.runpytest("--pdb", p1)

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