Merge pull request #10384 from tony/showlocals-negation

This commit is contained in:
Zac Hatfield-Dodds 2022-10-15 10:43:59 -07:00 committed by GitHub
commit 36b6384ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1 @@
The ``--no-showlocals`` flag has been added. This can be passed directly to tests to override ``--showlocals`` declared through ``addopts``.

View File

@ -12,8 +12,9 @@ Examples for modifying traceback printing:
.. code-block:: bash
pytest --showlocals # show local variables in tracebacks
pytest -l # show local variables (shortcut)
pytest --showlocals # show local variables in tracebacks
pytest -l # show local variables (shortcut)
pytest --no-showlocals # hide local variables (if addopts enables them)
pytest --tb=auto # (default) 'long' tracebacks for the first and last
# entry, but 'short' style for the other entries

View File

@ -178,6 +178,12 @@ def pytest_addoption(parser: Parser) -> None:
default=False,
help="Show locals in tracebacks (disabled by default)",
)
group._addoption(
"--no-showlocals",
action="store_false",
dest="showlocals",
help="Hide locals in tracebacks (negate --showlocals passed through addopts)",
)
group._addoption(
"--tb",
metavar="style",

View File

@ -998,6 +998,22 @@ class TestTerminalFunctional:
]
)
def test_noshowlocals_addopts_override(self, pytester: Pytester) -> None:
pytester.makeini("[pytest]\naddopts=--showlocals")
p1 = pytester.makepyfile(
"""
def test_noshowlocals():
x = 3
y = "x" * 5000
assert 0
"""
)
# Override global --showlocals for py.test via arg
result = pytester.runpytest(p1, "--no-showlocals")
result.stdout.no_fnmatch_line("x* = 3")
result.stdout.no_fnmatch_line("y* = 'xxxxxx*")
def test_showlocals_short(self, pytester: Pytester) -> None:
p1 = pytester.makepyfile(
"""