File tree 4 files changed +26
-2
lines changed
4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change
1
+ The ``--no-showlocals `` flag has been added. This can be passed directly to tests to override ``--showlocals `` declared through ``addopts ``.
Original file line number Diff line number Diff line change @@ -12,8 +12,9 @@ Examples for modifying traceback printing:
12
12
13
13
.. code-block :: bash
14
14
15
- pytest --showlocals # show local variables in tracebacks
16
- pytest -l # show local variables (shortcut)
15
+ pytest --showlocals # show local variables in tracebacks
16
+ pytest -l # show local variables (shortcut)
17
+ pytest --no-showlocals # hide local variables (if addopts enables them)
17
18
18
19
pytest --tb=auto # (default) 'long' tracebacks for the first and last
19
20
# entry, but 'short' style for the other entries
Original file line number Diff line number Diff line change @@ -178,6 +178,12 @@ def pytest_addoption(parser: Parser) -> None:
178
178
default = False ,
179
179
help = "Show locals in tracebacks (disabled by default)" ,
180
180
)
181
+ group ._addoption (
182
+ "--no-showlocals" ,
183
+ action = "store_false" ,
184
+ dest = "showlocals" ,
185
+ help = "Hide locals in tracebacks (negate --showlocals passed through addopts)" ,
186
+ )
181
187
group ._addoption (
182
188
"--tb" ,
183
189
metavar = "style" ,
Original file line number Diff line number Diff line change @@ -998,6 +998,22 @@ def test_showlocals():
998
998
]
999
999
)
1000
1000
1001
+ def test_noshowlocals_addopts_override (self , pytester : Pytester ) -> None :
1002
+ pytester .makeini ("[pytest]\n addopts=--showlocals" )
1003
+ p1 = pytester .makepyfile (
1004
+ """
1005
+ def test_noshowlocals():
1006
+ x = 3
1007
+ y = "x" * 5000
1008
+ assert 0
1009
+ """
1010
+ )
1011
+
1012
+ # Override global --showlocals for py.test via arg
1013
+ result = pytester .runpytest (p1 , "--no-showlocals" )
1014
+ result .stdout .no_fnmatch_line ("x* = 3" )
1015
+ result .stdout .no_fnmatch_line ("y* = 'xxxxxx*" )
1016
+
1001
1017
def test_showlocals_short (self , pytester : Pytester ) -> None :
1002
1018
p1 = pytester .makepyfile (
1003
1019
"""
You can’t perform that action at this time.
0 commit comments