support pytest.set_trace in collection
This commit is contained in:
		
							parent
							
								
									c5dee7b549
								
							
						
					
					
						commit
						7636dc76e0
					
				|  | @ -19,11 +19,13 @@ def pytest_configure(config): | ||||||
| class pytestPDB: | class pytestPDB: | ||||||
|     """ Pseudo PDB that defers to the real pdb. """ |     """ Pseudo PDB that defers to the real pdb. """ | ||||||
|     item = None |     item = None | ||||||
|  |     collector = None | ||||||
| 
 | 
 | ||||||
|     def set_trace(self): |     def set_trace(self): | ||||||
|         """ invoke PDB set_trace debugging, dropping any IO capturing. """ |         """ invoke PDB set_trace debugging, dropping any IO capturing. """ | ||||||
|         frame = sys._getframe().f_back |         frame = sys._getframe().f_back | ||||||
|         item = getattr(self, 'item', None) |         item = self.item or self.collector | ||||||
|  | 
 | ||||||
|         if item is not None: |         if item is not None: | ||||||
|             capman = item.config.pluginmanager.getplugin("capturemanager") |             capman = item.config.pluginmanager.getplugin("capturemanager") | ||||||
|             out, err = capman.suspendcapture() |             out, err = capman.suspendcapture() | ||||||
|  | @ -38,6 +40,14 @@ def pdbitem(item): | ||||||
|     pytestPDB.item = item |     pytestPDB.item = item | ||||||
| pytest_runtest_setup = pytest_runtest_call = pytest_runtest_teardown = pdbitem | pytest_runtest_setup = pytest_runtest_call = pytest_runtest_teardown = pdbitem | ||||||
| 
 | 
 | ||||||
|  | @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(): | def pytest_runtest_makereport(): | ||||||
|     pytestPDB.item = None |     pytestPDB.item = None | ||||||
|      |      | ||||||
|  |  | ||||||
|  | @ -144,6 +144,19 @@ class TestPDB: | ||||||
|         child.sendeof() |         child.sendeof() | ||||||
|         child.wait() |         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): |     def test_pdb_collection_failure_is_shown(self, testdir): | ||||||
|         p1 = testdir.makepyfile("""xxx """) |         p1 = testdir.makepyfile("""xxx """) | ||||||
|         result = testdir.runpytest("--pdb", p1) |         result = testdir.runpytest("--pdb", p1) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue