Merge pull request #10384 from tony/showlocals-negation
This commit is contained in:
commit
36b6384ff2
|
@ -0,0 +1 @@
|
||||||
|
The ``--no-showlocals`` flag has been added. This can be passed directly to tests to override ``--showlocals`` declared through ``addopts``.
|
|
@ -12,8 +12,9 @@ Examples for modifying traceback printing:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
pytest --showlocals # show local variables in tracebacks
|
pytest --showlocals # show local variables in tracebacks
|
||||||
pytest -l # show local variables (shortcut)
|
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
|
pytest --tb=auto # (default) 'long' tracebacks for the first and last
|
||||||
# entry, but 'short' style for the other entries
|
# entry, but 'short' style for the other entries
|
||||||
|
|
|
@ -178,6 +178,12 @@ def pytest_addoption(parser: Parser) -> None:
|
||||||
default=False,
|
default=False,
|
||||||
help="Show locals in tracebacks (disabled by default)",
|
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(
|
group._addoption(
|
||||||
"--tb",
|
"--tb",
|
||||||
metavar="style",
|
metavar="style",
|
||||||
|
|
|
@ -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:
|
def test_showlocals_short(self, pytester: Pytester) -> None:
|
||||||
p1 = pytester.makepyfile(
|
p1 = pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue