Skip to content

Commit b773a40

Browse files
committed
Properly report test failures
Assume the following test file `test_it.py`: ```python import pytest @pytest.fixture def foo(): return True @pytest.fixture(scope='session') def bar(foo): return False def test_it(bar): assert bar is False ``` When running pytest, it will error out because of the fixture scopes. Previously `pytest_reportportal` would wrongly mark the test as skipped, with this change it correctly marks it as failed. Fixes #44
1 parent e9526af commit b773a40

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

pytest_reportportal/listener.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@
66

77
class RPReportListener(object):
88
def __init__(self):
9-
# Identifier if TestItem is called:
10-
# if setup is failed, pytest will NOT call
11-
# TestItem and Result will not reported!
12-
self.called = False
13-
149
# Test Item result
1510
self.result = None
1611

1712
@pytest.hookimpl(hookwrapper=True)
1813
def pytest_runtest_protocol(self, item):
1914
PyTestService.start_pytest_item(item)
2015
yield
21-
item_result = self.result if self.called else 'SKIPPED'
22-
PyTestService.finish_pytest_item(item_result)
23-
self.called = False
16+
PyTestService.finish_pytest_item(self.result or 'SKIPPED')
2417

2518
@pytest.hookimpl(hookwrapper=True)
2619
def pytest_runtest_makereport(self):
@@ -33,14 +26,17 @@ def pytest_runtest_makereport(self):
3326
loglevel='ERROR',
3427
)
3528

36-
if report.when == 'call':
37-
self.called = True
29+
if report.when == 'setup':
30+
if report.failed:
31+
# This happens for example when a fixture fails to run
32+
# causing the test to error
33+
self.result = 'FAILED'
3834

35+
if report.when == 'call':
3936
if report.passed:
4037
item_result = 'PASSED'
41-
elif report.failed:
42-
item_result = 'FAILED'
43-
else:
38+
elif report.skipped:
4439
item_result = 'SKIPPED'
45-
40+
else:
41+
item_result = 'FAILED'
4642
self.result = item_result

0 commit comments

Comments
 (0)