File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Expand file tree Collapse file tree 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:
1212
1313.. code-block :: bash
1414
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)
1718
1819 pytest --tb=auto # (default) 'long' tracebacks for the first and last
1920 # 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:
178178 default = False ,
179179 help = "Show locals in tracebacks (disabled by default)" ,
180180 )
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+ )
181187 group ._addoption (
182188 "--tb" ,
183189 metavar = "style" ,
Original file line number Diff line number Diff line change @@ -998,6 +998,22 @@ def test_showlocals():
998998 ]
999999 )
10001000
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+
10011017 def test_showlocals_short (self , pytester : Pytester ) -> None :
10021018 p1 = pytester .makepyfile (
10031019 """
You can’t perform that action at this time.
0 commit comments