Skip to content

Commit e87d3d7

Browse files
authored
Merge pull request #5138 from ikonst/notify_exception_without_terminal
Fix dependencies on 'terminal' plugin
2 parents 008d043 + d67d68f commit e87d3d7

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Hugo van Kemenade
105105
Hui Wang (coldnight)
106106
Ian Bicking
107107
Ian Lesperance
108+
Ilya Konstantinov
108109
Ionuț Turturică
109110
Iwan Briquemont
110111
Jaap Broekhuizen

changelog/5139.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Eliminate core dependency on 'terminal' plugin.

src/_pytest/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def pytest_cmdline_parse(self, pluginmanager, args):
699699
return self
700700

701701
def notify_exception(self, excinfo, option=None):
702-
if option and option.fulltrace:
702+
if option and getattr(option, "fulltrace", False):
703703
style = "long"
704704
else:
705705
style = "native"

src/_pytest/nodes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def _repr_failure_py(self, excinfo, style=None):
248248
if excinfo.errisinstance(fm.FixtureLookupError):
249249
return excinfo.value.formatrepr()
250250
tbfilter = True
251-
if self.config.option.fulltrace:
251+
if self.config.getoption("fulltrace", False):
252252
style = "long"
253253
else:
254254
tb = _pytest._code.Traceback([excinfo.traceback[-1]])
@@ -260,12 +260,12 @@ def _repr_failure_py(self, excinfo, style=None):
260260
style = "long"
261261
# XXX should excinfo.getrepr record all data and toterminal() process it?
262262
if style is None:
263-
if self.config.option.tbstyle == "short":
263+
if self.config.getoption("tbstyle", "auto") == "short":
264264
style = "short"
265265
else:
266266
style = "long"
267267

268-
if self.config.option.verbose > 1:
268+
if self.config.getoption("verbose", 0) > 1:
269269
truncate_locals = False
270270
else:
271271
truncate_locals = True
@@ -279,7 +279,7 @@ def _repr_failure_py(self, excinfo, style=None):
279279
return excinfo.getrepr(
280280
funcargs=True,
281281
abspath=abspath,
282-
showlocals=self.config.option.showlocals,
282+
showlocals=self.config.getoption("showlocals", False),
283283
style=style,
284284
tbfilter=tbfilter,
285285
truncate_locals=truncate_locals,

src/_pytest/python.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def setup(self):
820820
self.obj = self._getobj()
821821

822822
def _prunetraceback(self, excinfo):
823-
if hasattr(self, "_obj") and not self.config.option.fulltrace:
823+
if hasattr(self, "_obj") and not self.config.getoption("fulltrace", False):
824824
code = _pytest._code.Code(get_real_func(self.obj))
825825
path, firstlineno = code.path, code.firstlineno
826826
traceback = excinfo.traceback
@@ -835,14 +835,14 @@ def _prunetraceback(self, excinfo):
835835
excinfo.traceback = ntraceback.filter()
836836
# issue364: mark all but first and last frames to
837837
# only show a single-line message for each frame
838-
if self.config.option.tbstyle == "auto":
838+
if self.config.getoption("tbstyle", "auto") == "auto":
839839
if len(excinfo.traceback) > 2:
840840
for entry in excinfo.traceback[1:-1]:
841841
entry.set_repr_style("short")
842842

843843
def repr_failure(self, excinfo, outerr=None):
844844
assert outerr is None, "XXX outerr usage is deprecated"
845-
style = self.config.option.tbstyle
845+
style = self.config.getoption("tbstyle", "auto")
846846
if style == "auto":
847847
style = "long"
848848
return self._repr_failure_py(excinfo, style=style)

src/_pytest/reports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def from_item_and_call(cls, item, call):
361361
longrepr = item.repr_failure(excinfo)
362362
else: # exception in setup or teardown
363363
longrepr = item._repr_failure_py(
364-
excinfo, style=item.config.option.tbstyle
364+
excinfo, style=item.config.getoption("tbstyle", "auto")
365365
)
366366
for rwhen, key, content in item._report_sections:
367367
sections.append(("Captured %s %s" % (key, rwhen), content))

testing/test_config.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ def test_notify_exception(testdir, capfd):
770770
config = testdir.parseconfig()
771771
with pytest.raises(ValueError) as excinfo:
772772
raise ValueError(1)
773-
config.notify_exception(excinfo)
773+
config.notify_exception(excinfo, config.option)
774774
out, err = capfd.readouterr()
775775
assert "ValueError" in err
776776

@@ -779,10 +779,17 @@ def pytest_internalerror(self, excrepr):
779779
return True
780780

781781
config.pluginmanager.register(A())
782-
config.notify_exception(excinfo)
782+
config.notify_exception(excinfo, config.option)
783783
out, err = capfd.readouterr()
784784
assert not err
785785

786+
config = testdir.parseconfig("-p", "no:terminal")
787+
with pytest.raises(ValueError) as excinfo:
788+
raise ValueError(1)
789+
config.notify_exception(excinfo, config.option)
790+
out, err = capfd.readouterr()
791+
assert "ValueError" in err
792+
786793

787794
def test_load_initial_conftest_last_ordering(testdir, _config_for_test):
788795
pm = _config_for_test.pluginmanager

0 commit comments

Comments
 (0)