Merge pull request #6181 from blueyed/maxfail-terminal-upstream
terminal: report ``session.shouldfail`` reason (``-x``)
This commit is contained in:
		
						commit
						a6e10cc2e3
					
				| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					The reason for a stopped session, e.g. with ``--maxfail`` / ``-x`` gets reported.
 | 
				
			||||||
| 
						 | 
					@ -676,7 +676,7 @@ class TerminalReporter:
 | 
				
			||||||
                            self._tw.line("{}{}".format(indent + "  ", line.strip()))
 | 
					                            self._tw.line("{}{}".format(indent + "  ", line.strip()))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.hookimpl(hookwrapper=True)
 | 
					    @pytest.hookimpl(hookwrapper=True)
 | 
				
			||||||
    def pytest_sessionfinish(self, exitstatus):
 | 
					    def pytest_sessionfinish(self, session: Session, exitstatus: ExitCode):
 | 
				
			||||||
        outcome = yield
 | 
					        outcome = yield
 | 
				
			||||||
        outcome.get_result()
 | 
					        outcome.get_result()
 | 
				
			||||||
        self._tw.line("")
 | 
					        self._tw.line("")
 | 
				
			||||||
| 
						 | 
					@ -691,9 +691,13 @@ class TerminalReporter:
 | 
				
			||||||
            self.config.hook.pytest_terminal_summary(
 | 
					            self.config.hook.pytest_terminal_summary(
 | 
				
			||||||
                terminalreporter=self, exitstatus=exitstatus, config=self.config
 | 
					                terminalreporter=self, exitstatus=exitstatus, config=self.config
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					        if session.shouldfail:
 | 
				
			||||||
 | 
					            self.write_sep("!", session.shouldfail, red=True)
 | 
				
			||||||
        if exitstatus == ExitCode.INTERRUPTED:
 | 
					        if exitstatus == ExitCode.INTERRUPTED:
 | 
				
			||||||
            self._report_keyboardinterrupt()
 | 
					            self._report_keyboardinterrupt()
 | 
				
			||||||
            del self._keyboardinterrupt_memo
 | 
					            del self._keyboardinterrupt_memo
 | 
				
			||||||
 | 
					        elif session.shouldstop:
 | 
				
			||||||
 | 
					            self.write_sep("!", session.shouldstop, red=True)
 | 
				
			||||||
        self.summary_stats()
 | 
					        self.summary_stats()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.hookimpl(hookwrapper=True)
 | 
					    @pytest.hookimpl(hookwrapper=True)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -852,11 +852,15 @@ def test_exit_on_collection_with_maxfail_smaller_than_n_errors(testdir):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res = testdir.runpytest("--maxfail=1")
 | 
					    res = testdir.runpytest("--maxfail=1")
 | 
				
			||||||
    assert res.ret == 1
 | 
					    assert res.ret == 1
 | 
				
			||||||
 | 
					 | 
				
			||||||
    res.stdout.fnmatch_lines(
 | 
					    res.stdout.fnmatch_lines(
 | 
				
			||||||
        ["*ERROR collecting test_02_import_error.py*", "*No module named *asdfa*"]
 | 
					        [
 | 
				
			||||||
 | 
					            "collected 1 item / 1 error",
 | 
				
			||||||
 | 
					            "*ERROR collecting test_02_import_error.py*",
 | 
				
			||||||
 | 
					            "*No module named *asdfa*",
 | 
				
			||||||
 | 
					            "*! stopping after 1 failures !*",
 | 
				
			||||||
 | 
					            "*= 1 error in *",
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					 | 
				
			||||||
    res.stdout.no_fnmatch_line("*test_03*")
 | 
					    res.stdout.no_fnmatch_line("*test_03*")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -869,7 +873,6 @@ def test_exit_on_collection_with_maxfail_bigger_than_n_errors(testdir):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res = testdir.runpytest("--maxfail=4")
 | 
					    res = testdir.runpytest("--maxfail=4")
 | 
				
			||||||
    assert res.ret == 2
 | 
					    assert res.ret == 2
 | 
				
			||||||
 | 
					 | 
				
			||||||
    res.stdout.fnmatch_lines(
 | 
					    res.stdout.fnmatch_lines(
 | 
				
			||||||
        [
 | 
					        [
 | 
				
			||||||
            "collected 2 items / 2 errors",
 | 
					            "collected 2 items / 2 errors",
 | 
				
			||||||
| 
						 | 
					@ -877,6 +880,8 @@ def test_exit_on_collection_with_maxfail_bigger_than_n_errors(testdir):
 | 
				
			||||||
            "*No module named *asdfa*",
 | 
					            "*No module named *asdfa*",
 | 
				
			||||||
            "*ERROR collecting test_03_import_error.py*",
 | 
					            "*ERROR collecting test_03_import_error.py*",
 | 
				
			||||||
            "*No module named *asdfa*",
 | 
					            "*No module named *asdfa*",
 | 
				
			||||||
 | 
					            "*! Interrupted: 2 errors during collection !*",
 | 
				
			||||||
 | 
					            "*= 2 errors in *",
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -963,7 +963,31 @@ class TestGenericReporting:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        result = testdir.runpytest("--maxfail=2", *option.args)
 | 
					        result = testdir.runpytest("--maxfail=2", *option.args)
 | 
				
			||||||
        result.stdout.fnmatch_lines(
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
            ["*def test_1():*", "*def test_2():*", "*2 failed*"]
 | 
					            [
 | 
				
			||||||
 | 
					                "*def test_1():*",
 | 
				
			||||||
 | 
					                "*def test_2():*",
 | 
				
			||||||
 | 
					                "*! stopping after 2 failures !*",
 | 
				
			||||||
 | 
					                "*2 failed*",
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_maxfailures_with_interrupted(self, testdir):
 | 
				
			||||||
 | 
					        testdir.makepyfile(
 | 
				
			||||||
 | 
					            """
 | 
				
			||||||
 | 
					            def test(request):
 | 
				
			||||||
 | 
					                request.session.shouldstop = "session_interrupted"
 | 
				
			||||||
 | 
					                assert 0
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        result = testdir.runpytest("--maxfail=1", "-ra")
 | 
				
			||||||
 | 
					        result.stdout.fnmatch_lines(
 | 
				
			||||||
 | 
					            [
 | 
				
			||||||
 | 
					                "*= short test summary info =*",
 | 
				
			||||||
 | 
					                "FAILED *",
 | 
				
			||||||
 | 
					                "*! stopping after 1 failures !*",
 | 
				
			||||||
 | 
					                "*! session_interrupted !*",
 | 
				
			||||||
 | 
					                "*= 1 failed in*",
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_tb_option(self, testdir, option):
 | 
					    def test_tb_option(self, testdir, option):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue