From ee57a2ad451e813b99ac49e8ead1657f57b8d420 Mon Sep 17 00:00:00 2001 From: q0w <43147888+q0w@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:28:33 +0300 Subject: [PATCH] Check if config args and args_source exist --- AUTHORS | 1 + changelog/10626.bugfix.rst | 1 + src/_pytest/main.py | 2 +- src/_pytest/terminal.py | 6 ++++-- testing/python/fixtures.py | 4 ++++ 5 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelog/10626.bugfix.rst diff --git a/AUTHORS b/AUTHORS index 7cf1748e6..f345c0cab 100644 --- a/AUTHORS +++ b/AUTHORS @@ -290,6 +290,7 @@ Prashant Sharma Pulkit Goyal Punyashloka Biswal Quentin Pradet +q0w Ralf Schmitt Ralph Giles Ram Rachum diff --git a/changelog/10626.bugfix.rst b/changelog/10626.bugfix.rst new file mode 100644 index 000000000..510b05cdf --- /dev/null +++ b/changelog/10626.bugfix.rst @@ -0,0 +1 @@ +Check if ``Config.args`` and ``Config.args_source`` exist. diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 61fb7eaa4..8bbc1eec1 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -619,7 +619,7 @@ class Session(nodes.FSCollector): and ``session.items`` is empty. """ if args is None: - args = self.config.args + args = self.config.args if hasattr(self.config, "args") else () self.trace("perform_collect", self, args) self.trace.root.indent += 1 diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index d967a3ee6..34bc9719e 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -737,8 +737,10 @@ class TerminalReporter: if config.inipath: line += ", configfile: " + bestrelpath(config.rootpath, config.inipath) - - if config.args_source == Config.ArgsSource.TESTPATHS: + if ( + hasattr(config, "args_source") + and config.args_source == Config.ArgsSource.TESTPATHS + ): testpaths: List[str] = config.getini("testpaths") line += ", testpaths: {}".format(", ".join(testpaths)) diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 3ce5cb34d..d996f80bb 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -3338,6 +3338,10 @@ class TestShowFixtures: config = pytester.parseconfigure("--funcargs") assert config.option.showfixtures + def test_show_help(self, pytester: Pytester) -> None: + result = pytester.runpytest("--fixtures", "--help") + assert not result.ret + def test_show_fixtures(self, pytester: Pytester) -> None: result = pytester.runpytest("--fixtures") result.stdout.fnmatch_lines(