From 671aa05c1e614ca4236f5be7a951d6eded4c0974 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 18 Mar 2020 13:49:39 +0100 Subject: [PATCH] Remove import of pkg_resources for parsing pytest version Ref: https://github.com/pytest-dev/pytest-django/pull/744#issuecomment-600581325 --- pytest_django/plugin.py | 4 ++-- tests/test_unittest.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 4deca87f3..8b6e4ce79 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -12,7 +12,6 @@ import types import pytest -from pkg_resources import parse_version from .django_compat import is_django_unittest # noqa from .fixtures import django_assert_num_queries # noqa @@ -53,7 +52,8 @@ PY2 = sys.version_info[0] == 2 # pytest 4.2 handles unittest setup/teardown itself via wrapping fixtures. -_handle_unittest_methods = parse_version(pytest.__version__) < parse_version("4.2") +_pytest_version_info = tuple(int(x) for x in pytest.__version__.split(".", 2)[:2]) +_handle_unittest_methods = _pytest_version_info < (4, 2) _report_header = [] diff --git a/tests/test_unittest.py b/tests/test_unittest.py index 985e868ed..1f637e374 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -1,7 +1,7 @@ import pytest from django.test import TestCase -from pkg_resources import parse_version +from pytest_django.plugin import _pytest_version_info from pytest_django_test.app.models import Item @@ -146,7 +146,7 @@ def test_pass(self): expected_lines = [ "* ERROR at setup of TestFoo.test_pass *", ] - if parse_version(pytest.__version__) < parse_version("4.2"): + if _pytest_version_info < (4, 2): expected_lines += [ "E *Failed: .setUpClass should be a classmethod", # noqa:E501 ]