Skip to content

Commit d73f265

Browse files
author
Dmitriy Gumeniuk
authored
Merge pull request #141 from iivanou/pytest_warning_compatibility
Handle PytestWarning import error in old Pytest versions
2 parents c0d850a + 1a40044 commit d73f265

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

pytest_reportportal/errors.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""This module includes exceptions used in the package."""
2+
3+
4+
class PytestWarning(UserWarning):
5+
"""Pytest warning exception.
6+
7+
This exception is about to stub absent PytestWarning in Pytest versions
8+
up to 3.8.0. Get rid of this code once we drop support for Pytest versions
9+
below 3.8.0.
10+
"""
11+
pass

pytest_reportportal/listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _add_issue_info(self, item, report):
112112

113113
issue_type = "TI" if issue_type is None else issue_type
114114

115-
if issue_type and self.PyTestService.issue_types \
115+
if issue_type and getattr(self.PyTestService, 'issue_types', False) \
116116
and (issue_type in self.PyTestService.issue_types):
117117
if comment:
118118
self.issue['comment'] = comment

pytest_reportportal/service.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@
1414
except pkg_resources.VersionConflict:
1515
from _pytest.main import File, Item
1616

17+
try:
18+
pkg_resources.get_distribution('pytest >= 3.8.0')
19+
from _pytest.warning_types import PytestWarning
20+
except pkg_resources.VersionConflict:
21+
from pytest_reportportal.errors import PytestWarning
22+
23+
1724
from _pytest.python import Class, Function, Instance, Module
1825
from _pytest.unittest import TestCaseFunction, UnitTestCase
19-
from _pytest.warning_types import PytestWarning
26+
2027
from reportportal_client import ReportPortalServiceAsync
2128
from six import with_metaclass
2229
from six.moves import queue

0 commit comments

Comments
 (0)