Skip to content

Commit c65dc70

Browse files
authored
Remove import of pkg_resources for parsing pytest version (#826)
Speeds up `pytest --version` from 249ms to 204ms. Ref: #744 (comment)
1 parent 46f59f7 commit c65dc70

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pytest_django/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import types
1313

1414
import pytest
15-
from pkg_resources import parse_version
1615

1716
from .django_compat import is_django_unittest # noqa
1817
from .fixtures import django_assert_num_queries # noqa
@@ -53,7 +52,8 @@
5352
PY2 = sys.version_info[0] == 2
5453

5554
# pytest 4.2 handles unittest setup/teardown itself via wrapping fixtures.
56-
_handle_unittest_methods = parse_version(pytest.__version__) < parse_version("4.2")
55+
_pytest_version_info = tuple(int(x) for x in pytest.__version__.split(".", 2)[:2])
56+
_handle_unittest_methods = _pytest_version_info < (4, 2)
5757

5858
_report_header = []
5959

tests/test_unittest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from django.test import TestCase
3-
from pkg_resources import parse_version
43

4+
from pytest_django.plugin import _pytest_version_info
55
from pytest_django_test.app.models import Item
66

77

@@ -146,7 +146,7 @@ def test_pass(self):
146146
expected_lines = [
147147
"* ERROR at setup of TestFoo.test_pass *",
148148
]
149-
if parse_version(pytest.__version__) < parse_version("4.2"):
149+
if _pytest_version_info < (4, 2):
150150
expected_lines += [
151151
"E *Failed: <class 'tpkg.test_the_test.TestFoo'>.setUpClass should be a classmethod", # noqa:E501
152152
]

0 commit comments

Comments
 (0)