doctest: handle BdbQuit
Map `BdbQuit` exception to `outcomes.Exit`. This is necessary since we are not wrapping `pdb.set_trace` there, and therefore our `do_quit` is not called.
This commit is contained in:
		
							parent
							
								
									faf222f8fb
								
							
						
					
					
						commit
						63d517645c
					
				|  | @ -1,4 +1,5 @@ | |||
| """ discover and run doctests in modules and test files.""" | ||||
| import bdb | ||||
| import inspect | ||||
| import platform | ||||
| import sys | ||||
|  | @ -7,6 +8,7 @@ import warnings | |||
| from contextlib import contextmanager | ||||
| 
 | ||||
| import pytest | ||||
| from _pytest import outcomes | ||||
| from _pytest._code.code import ExceptionInfo | ||||
| from _pytest._code.code import ReprFileLocation | ||||
| from _pytest._code.code import TerminalRepr | ||||
|  | @ -155,6 +157,8 @@ def _init_runner_class(): | |||
|         def report_unexpected_exception(self, out, test, example, exc_info): | ||||
|             if isinstance(exc_info[1], Skipped): | ||||
|                 raise exc_info[1] | ||||
|             if isinstance(exc_info[1], bdb.BdbQuit): | ||||
|                 outcomes.exit("Quitting debugger") | ||||
|             failure = doctest.UnexpectedException(test, example, exc_info) | ||||
|             if self.continue_on_failure: | ||||
|                 out.append(failure) | ||||
|  |  | |||
|  | @ -458,7 +458,6 @@ class TestPDB: | |||
|     def test_pdb_interaction_doctest(self, testdir, monkeypatch): | ||||
|         p1 = testdir.makepyfile( | ||||
|             """ | ||||
|             import pytest | ||||
|             def function_1(): | ||||
|                 ''' | ||||
|                 >>> i = 0 | ||||
|  | @ -477,9 +476,32 @@ class TestPDB: | |||
| 
 | ||||
|         child.sendeof() | ||||
|         rest = child.read().decode("utf8") | ||||
|         assert "! _pytest.outcomes.Exit: Quitting debugger !" in rest | ||||
|         assert "BdbQuit" not in rest | ||||
|         assert "1 failed" in rest | ||||
|         self.flush(child) | ||||
| 
 | ||||
|     def test_doctest_set_trace_quit(self, testdir, monkeypatch): | ||||
|         p1 = testdir.makepyfile( | ||||
|             """ | ||||
|             def function_1(): | ||||
|                 ''' | ||||
|                 >>> __import__('pdb').set_trace() | ||||
|                 ''' | ||||
|         """ | ||||
|         ) | ||||
|         # NOTE: does not use pytest.set_trace, but Python's patched pdb, | ||||
|         #       therefore "-s" is required. | ||||
|         child = testdir.spawn_pytest("--doctest-modules --pdb -s %s" % p1) | ||||
|         child.expect("Pdb") | ||||
|         child.sendline("q") | ||||
|         rest = child.read().decode("utf8") | ||||
| 
 | ||||
|         assert "! _pytest.outcomes.Exit: Quitting debugger !" in rest | ||||
|         assert "= no tests ran in" in rest | ||||
|         assert "BdbQuit" not in rest | ||||
|         assert "UNEXPECTED EXCEPTION" not in rest | ||||
| 
 | ||||
|     def test_pdb_interaction_capturing_twice(self, testdir): | ||||
|         p1 = testdir.makepyfile( | ||||
|             """ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue