From 4e723d67508a72878e7afc014d4672944c94cd4f Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 27 Jun 2019 10:24:29 -0700 Subject: [PATCH] Fix crash when discovery fails while using `-p no:terminal` --- changelog/5505.bugfix.rst | 1 + src/_pytest/nodes.py | 2 +- testing/test_config.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 changelog/5505.bugfix.rst 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