Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃敡 --no-showlocals to negate addopts w/ --showlocals #10384

Merged
merged 4 commits into from Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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