From 872656962cecff5171975541a0d831503be17350 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 18 Aug 2018 14:41:24 +0200 Subject: [PATCH 1/3] Use pathlib2 The dependency on `pathlib` was added in #631. A backport is needed for Python <3.4. The `pathlib` package [on PyPI](https://pypi.org/project/pathlib/) is maintenance-only and comes with a message about using `pathlib2` for an up-to-date version, still importable as `pathlib`. Also `pytest` itself uses `pathlib2` so currently I'm getting both packages installed, one on top of the other, woops! This change in `setup.py` seems to be all that's needed to switch. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 01990b7fc..5b50f6636 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ def read(fname): setup_requires=['setuptools_scm>=1.11.1'], install_requires=[ 'pytest>=3.6', - 'pathlib;python_version<"3.4"', + 'pathlib2;python_version<"3.4"', ], extras_require={ 'docs': [ From 889951df3ae2baa827977a536bb3375b7c1effd2 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 18 Aug 2018 15:05:22 +0200 Subject: [PATCH 2/3] change import name --- pytest_django/plugin.py | 2 +- tests/conftest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 332e3a439..eb84cf78a 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -11,7 +11,7 @@ import sys import types -import pathlib +import pathlib2 as pathlib import pytest from .django_compat import is_django_unittest # noqa diff --git a/tests/conftest.py b/tests/conftest.py index 1ee253d5a..dcb828bad 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,7 @@ import shutil from textwrap import dedent -import pathlib +import pathlib2 as pathlib import pytest import six from django.conf import settings From e9e0d57b84114d898c52c296b438298a678ae446 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 18 Aug 2018 15:40:13 +0200 Subject: [PATCH 3/3] conditional for python 3.4+ --- pytest_django/plugin.py | 6 +++++- tests/conftest.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index eb84cf78a..ce9591c23 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -11,7 +11,6 @@ import sys import types -import pathlib2 as pathlib import pytest from .django_compat import is_django_unittest # noqa @@ -38,6 +37,11 @@ from .lazy_django import django_settings_is_configured, skip_if_no_django +try: + import pathlib +except ImportError: + import pathlib2 as pathlib + SETTINGS_MODULE_ENV = 'DJANGO_SETTINGS_MODULE' CONFIGURATION_ENV = 'DJANGO_CONFIGURATION' diff --git a/tests/conftest.py b/tests/conftest.py index dcb828bad..d14389612 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,13 +2,17 @@ import shutil from textwrap import dedent -import pathlib2 as pathlib import pytest import six from django.conf import settings from pytest_django_test.db_helpers import DB_NAME, TEST_DB_NAME +try: + import pathlib +except ImportError: + import pathlib2 as pathlib + pytest_plugins = 'pytester' REPOSITORY_ROOT = pathlib.Path(__file__).parent