diff --git a/changelog/5505.bugfix.rst b/changelog/5505.bugfix.rst new file mode 100644 index 000000000..2d0a53b39 --- /dev/null +++ b/changelog/5505.bugfix.rst @@ -0,0 +1 @@ +Fix crash when discovery fails while using ``-p no:terminal``. diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index f476e4141..491cf9d2c 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -323,7 +323,7 @@ class Collector(Node): # Respect explicit tbstyle option, but default to "short" # (None._repr_failure_py defaults to "long" without "fulltrace" option). - tbstyle = self.config.getoption("tbstyle") + tbstyle = self.config.getoption("tbstyle", "auto") if tbstyle == "auto": tbstyle = "short" diff --git a/testing/test_config.py b/testing/test_config.py index b9fc388d2..ff993e401 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -741,10 +741,10 @@ def test_config_in_subdirectory_colon_command_line_issue2148(testdir): **{ "conftest": conftest_source, "subdir/conftest": conftest_source, - "subdir/test_foo": """ + "subdir/test_foo": """\ def test_foo(pytestconfig): assert pytestconfig.getini('foo') == 'subdir' - """, + """, } ) @@ -777,6 +777,12 @@ def test_notify_exception(testdir, capfd): assert "ValueError" in err +def test_no_terminal_discovery_error(testdir): + testdir.makepyfile("raise TypeError('oops!')") + result = testdir.runpytest("-p", "no:terminal", "--collect-only") + assert result.ret == ExitCode.INTERRUPTED + + def test_load_initial_conftest_last_ordering(testdir, _config_for_test): pm = _config_for_test.pluginmanager