Skip to content

Commit

Permalink
Fix crash if --cache-show and --help are passed at the same time
Browse files Browse the repository at this point in the history
Closes pytest-dev#10592

(cherry picked from commit 4d4ed42)
  • Loading branch information
markshao authored and nicoddemus committed Jan 19, 2023
1 parent 94c05bc commit 5bf361f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Expand Up @@ -374,6 +374,8 @@ Xixi Zhao
Xuan Luong
Xuecong Liao
Yoav Caspi
Yuliang Shao
Yusuke Kadowaki
Yuval Shimon
Zac Hatfield-Dodds
Zachary Kneupper
Expand Down
1 change: 1 addition & 0 deletions changelog/10592.bugfix.rst
@@ -0,0 +1 @@
Fixed crash if `--cache-show` and `--help` are passed at the same time.
3 changes: 1 addition & 2 deletions src/_pytest/cacheprovider.py
Expand Up @@ -32,7 +32,6 @@
from _pytest.python import Package
from _pytest.reports import TestReport


README_CONTENT = """\
# pytest cache directory #
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions testing/test_cacheprovider.py
Expand Up @@ -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

0 comments on commit 5bf361f

Please sign in to comment.