Skip to content

Commit

Permalink
Merge pull request #10384 from tony/showlocals-negation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Oct 15, 2022
2 parents 31df38f + 2a33e6a commit 36b6384
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/10381.improvement.rst
@@ -0,0 +1 @@
The ``--no-showlocals`` flag has been added. This can be passed directly to tests to override ``--showlocals`` declared through ``addopts``.
5 changes: 3 additions & 2 deletions doc/en/how-to/output.rst
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/_pytest/terminal.py
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions testing/test_terminal.py
Expand Up @@ -998,6 +998,22 @@ def test_showlocals():
]
)

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(
"""
Expand Down

0 comments on commit 36b6384

Please sign in to comment.