wrap_session: restore old behavior for initstate=1
This commit is contained in:
		
							parent
							
								
									1c9dcf1f39
								
							
						
					
					
						commit
						cc90bcce4c
					
				|  | @ -214,10 +214,13 @@ def wrap_session(config, doit): | |||
|         except (KeyboardInterrupt, exit.Exception): | ||||
|             excinfo = _pytest._code.ExceptionInfo.from_current() | ||||
|             exitstatus = EXIT_INTERRUPTED | ||||
|             if initstate <= 2 and isinstance(excinfo.value, exit.Exception): | ||||
|                 sys.stderr.write("{}: {}\n".format(excinfo.typename, excinfo.value.msg)) | ||||
|             if isinstance(excinfo.value, exit.Exception): | ||||
|                 if excinfo.value.returncode is not None: | ||||
|                     exitstatus = excinfo.value.returncode | ||||
|                 if initstate < 2: | ||||
|                     sys.stderr.write( | ||||
|                         "{}: {}\n".format(excinfo.typename, excinfo.value.msg) | ||||
|                     ) | ||||
|             config.hook.pytest_keyboard_interrupt(excinfo=excinfo) | ||||
|             session.exitstatus = exitstatus | ||||
|         except:  # noqa | ||||
|  |  | |||
|  | @ -1015,7 +1015,8 @@ class TestTraceOption: | |||
|         rest = child.read().decode("utf8") | ||||
|         assert "2 passed in" in rest | ||||
|         assert "reading from stdin while output" not in rest | ||||
|         assert "Exit: Quitting debugger" in child.before.decode("utf8") | ||||
|         # Only printed once - not on stderr. | ||||
|         assert "Exit: Quitting debugger" not in child.before.decode("utf8") | ||||
|         TestPDB.flush(child) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -580,8 +580,24 @@ def test_pytest_exit_returncode(testdir): | |||
|     """ | ||||
|     ) | ||||
|     result = testdir.runpytest() | ||||
|     result.stdout.fnmatch_lines(["*! *Exit: some exit msg !*"]) | ||||
|     assert result.stderr.lines == [""] | ||||
|     assert result.ret == 99 | ||||
| 
 | ||||
|     # It prints to stderr also in case of exit during pytest_sessionstart. | ||||
|     testdir.makeconftest( | ||||
|         """ | ||||
|         import pytest | ||||
| 
 | ||||
|         def pytest_sessionstart(): | ||||
|             pytest.exit("during_sessionstart", 98) | ||||
|         """ | ||||
|     ) | ||||
|     result = testdir.runpytest() | ||||
|     result.stdout.fnmatch_lines(["*! *Exit: during_sessionstart !*"]) | ||||
|     assert result.stderr.lines == ["Exit: during_sessionstart", ""] | ||||
|     assert result.ret == 98 | ||||
| 
 | ||||
| 
 | ||||
| def test_pytest_fail_notrace_runtest(testdir): | ||||
|     """Test pytest.fail(..., pytrace=False) does not show tracebacks during test run.""" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue