-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpytest_unstable.py
More file actions
25 lines (17 loc) · 910 Bytes
/
pytest_unstable.py
File metadata and controls
25 lines (17 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-
import pytest
def pytest_configure(config):
config.addinivalue_line("markers", "unstable")
def _test_is_unstable(node):
return any(marker.name == 'unstable' for marker in node.own_markers)
@pytest.hookimpl(trylast=True)
def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
if exitstatus == pytest.ExitCode.TESTS_FAILED:
reporter = session.config.pluginmanager.get_plugin('terminalreporter')
errors = reporter.getreports("error")
failed_tests = reporter.getreports("failed")
unstable_tests = [test.nodeid for test in session.items if _test_is_unstable(test)]
# Remove elements from failed_tests if unstable
non_unstable_tests = [test for test in failed_tests if test not in unstable_tests]
if len(non_unstable_tests) == 0 and len(errors) == 0:
session.exitstatus = pytest.ExitCode.OK