From d044e9f642edd5bea5bac16c1952cb365e6ded34 Mon Sep 17 00:00:00 2001 From: markshao Date: Sat, 24 Dec 2022 11:28:55 +0800 Subject: [PATCH 1/6] fix the error when mix-use the cache-show and help option --- src/_pytest/config/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 25f156f8b20..b997e47d9f3 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1074,6 +1074,12 @@ def pytest_cmdline_parse( ) raise + except PrintHelp: + self._parser._getparser().print_help() + sys.stdout.write( + "\nNOTE: displaying only minimal help due to UsageError.\n\n" + ) + raise UsageError return self @@ -1368,7 +1374,7 @@ def parse(self, args: List[str], addopts: bool = True) -> None: self.args = args self.args_source = source except PrintHelp: - pass + raise def issue_config_time_warning(self, warning: Warning, stacklevel: int) -> None: """Issue and handle a warning during the "configure" stage. From 032551a336add78166d9b9582b70c87eb46c810e Mon Sep 17 00:00:00 2001 From: markshao Date: Sat, 24 Dec 2022 11:38:06 +0800 Subject: [PATCH 2/6] add to author --- AUTHORS | 1 + changelog/10592.bugfix.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog/10592.bugfix.rst diff --git a/AUTHORS b/AUTHORS index a4ca9926760..4a87b89e74c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -377,6 +377,7 @@ Xixi Zhao Xuan Luong Xuecong Liao Yoav Caspi +Yuliang Shao Yusuke Kadowaki Yuval Shimon Zac Hatfield-Dodds diff --git a/changelog/10592.bugfix.rst b/changelog/10592.bugfix.rst new file mode 100644 index 00000000000..6dc9705174a --- /dev/null +++ b/changelog/10592.bugfix.rst @@ -0,0 +1 @@ +Fix the bug "--cache-show --help" triggers an internal error From e7f431e7dda4212d3aad5b6243ce647bbca65b27 Mon Sep 17 00:00:00 2001 From: markshao Date: Sat, 24 Dec 2022 15:22:18 +0800 Subject: [PATCH 3/6] Revert "fix the error when mix-use the cache-show and help option" This reverts commit d044e9f642edd5bea5bac16c1952cb365e6ded34. --- src/_pytest/config/__init__.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index b997e47d9f3..25f156f8b20 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1074,12 +1074,6 @@ def pytest_cmdline_parse( ) raise - except PrintHelp: - self._parser._getparser().print_help() - sys.stdout.write( - "\nNOTE: displaying only minimal help due to UsageError.\n\n" - ) - raise UsageError return self @@ -1374,7 +1368,7 @@ def parse(self, args: List[str], addopts: bool = True) -> None: self.args = args self.args_source = source except PrintHelp: - raise + pass def issue_config_time_warning(self, warning: Warning, stacklevel: int) -> None: """Issue and handle a warning during the "configure" stage. From 5635bb3572175a75c2267f8236149e0b83e96aa4 Mon Sep 17 00:00:00 2001 From: markshao Date: Sat, 24 Dec 2022 15:56:44 +0800 Subject: [PATCH 4/6] fix pre-commit --- src/_pytest/cacheprovider.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 777c1b0b05a..c236dd4176b 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -32,7 +32,6 @@ from _pytest.python import Package from _pytest.reports import TestReport - README_CONTENT = """\ # pytest cache directory # @@ -492,7 +491,7 @@ def pytest_addoption(parser: Parser) -> None: def pytest_cmdline_main(config: Config) -> Optional[Union[int, ExitCode]]: - if config.option.cacheshow: + if config.option.cacheshow and not config.option.help: from _pytest.main import wrap_session return wrap_session(config, cacheshow) From c5bfb99d5c5eb463a84576c5eda878d7920d9123 Mon Sep 17 00:00:00 2001 From: Ramsey <37647536@qq.com> Date: Fri, 13 Jan 2023 21:43:09 +0800 Subject: [PATCH 5/6] Update changelog/10592.bugfix.rst update rst message Co-authored-by: Bruno Oliveira --- changelog/10592.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/10592.bugfix.rst b/changelog/10592.bugfix.rst index 6dc9705174a..62c1c7e3c34 100644 --- a/changelog/10592.bugfix.rst +++ b/changelog/10592.bugfix.rst @@ -1 +1 @@ -Fix the bug "--cache-show --help" triggers an internal error +Fixed crash if `--cache-show` and `--help` are passed at the same time. From 8bc96d4aa86873e37d354278c7620bc1887f796d Mon Sep 17 00:00:00 2001 From: markshao Date: Fri, 13 Jan 2023 21:59:05 +0800 Subject: [PATCH 6/6] add integration test --- testing/test_cacheprovider.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index 2baa3c8f189..c381a8448ce 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -1249,3 +1249,8 @@ def test_cachedir_tag(pytester: Pytester) -> None: cache.set("foo", "bar") cachedir_tag_path = cache._cachedir.joinpath("CACHEDIR.TAG") assert cachedir_tag_path.read_bytes() == CACHEDIR_TAG_CONTENT + + +def test_clioption_with_cacheshow_and_help(pytester: Pytester) -> None: + result = pytester.runpytest("--cache-show", "--help") + assert result.ret == 0