From ee408190d6a371385a827cba54a375827ad78c34 Mon Sep 17 00:00:00 2001 From: Simon Kohlmeyer Date: Sun, 11 Mar 2018 18:38:47 +0100 Subject: [PATCH 1/2] Remove py dependency py is in maintenance mode and there are modern alternatives. --- pytest_django/plugin.py | 44 ++++++++++++++++++++--------------------- setup.py | 6 +++++- tests/conftest.py | 11 ++++++----- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 5d4f323a7..232798bdf 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -11,7 +11,7 @@ import sys import types -import py +import pathlib import pytest from .django_compat import is_django_unittest # noqa @@ -87,13 +87,6 @@ def pytest_addoption(parser): type='bool', default=False) -def _exists(path, ignore=EnvironmentError): - try: - return path.check() - except ignore: - return False - - PROJECT_FOUND = ('pytest-django found a Django project in %s ' '(it contains manage.py) and added it to the Python path.\n' 'If this is wrong, add "django_find_project = false" to ' @@ -120,21 +113,28 @@ def _handle_import_error(extra_message): def _add_django_project_to_path(args): - args = [x for x in args if not str(x).startswith("-")] - - if not args: - args = [py.path.local()] - - for arg in args: - arg = py.path.local(arg) - - for base in arg.parts(reverse=True): - manage_py_try = base.join('manage.py') - - if _exists(manage_py_try): - sys.path.insert(0, str(base)) - return PROJECT_FOUND % base + def is_django_project(path): + return path.is_dir() and (path / 'manage.py').exists() + + def find_django_path(args): + args = [pathlib.Path(x) for x in args if not str(x).startswith("-")] + args = [p for p in args if p.is_dir()] + + if not args: + args = [pathlib.Path.cwd()] + + for arg in args: + if is_django_project(arg): + return arg + for parent in arg.parents: + if is_django_project(parent): + return parent + return None + project_dir = find_django_path(args) + if project_dir: + sys.path.insert(0, str(project_dir)) + return PROJECT_FOUND % project_dir return PROJECT_NOT_FOUND diff --git a/setup.py b/setup.py index 0901054df..3f4a10e77 100755 --- a/setup.py +++ b/setup.py @@ -30,7 +30,11 @@ def read(fname): long_description=read('README.rst'), python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', setup_requires=['setuptools_scm>=1.11.1'], - install_requires=['pytest>=3.6'], + install_requires=[ + 'pytest>=3.6', + 'pathlib;python_version<"3.4"', + 'six', + ], extras_require={ 'docs': [ 'sphinx', diff --git a/tests/conftest.py b/tests/conftest.py index 8ea211222..debdc7442 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,15 +2,16 @@ import shutil from textwrap import dedent -import py +import pathlib import pytest +import six from django.conf import settings from pytest_django_test.db_helpers import DB_NAME, TEST_DB_NAME pytest_plugins = 'pytester' -REPOSITORY_ROOT = py.path.local(__file__).join('..') +REPOSITORY_ROOT = pathlib.Path(__file__).parent def pytest_configure(config): @@ -99,12 +100,12 @@ def django_testdir(request, testdir, monkeypatch): tpkg_path.ensure('__init__.py') - app_source = REPOSITORY_ROOT.dirpath('pytest_django_test/app') + app_source = REPOSITORY_ROOT / '../pytest_django_test/app' test_app_path = tpkg_path.join('app') # Copy the test app to make it available in the new test run - shutil.copytree(py.builtin._totext(app_source), - py.builtin._totext(test_app_path)) + shutil.copytree(six.text_type(app_source), + six.text_type(test_app_path)) tpkg_path.join("the_settings.py").write(test_settings) monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'tpkg.the_settings') From f2ea236a70873fe763a5b6d50678743e2238b297 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 26 Jul 2018 12:57:16 +0200 Subject: [PATCH 2/2] Add testing extras_require, and move six to it --- setup.py | 10 ++++++++-- tox.ini | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 3f4a10e77..f53e112eb 100755 --- a/setup.py +++ b/setup.py @@ -33,13 +33,19 @@ def read(fname): install_requires=[ 'pytest>=3.6', 'pathlib;python_version<"3.4"', - 'six', ], extras_require={ 'docs': [ 'sphinx', 'sphinx_rtd_theme', - ] + ], + 'testing': [ + 'pytest>=3.6', + 'Django', + 'django-configurations==2.0', + 'pytest-xdist==1.15', + 'six', + ], }, classifiers=['Development Status :: 5 - Production/Stable', 'Framework :: Django', diff --git a/tox.ini b/tox.ini index 068760b21..3d945e526 100644 --- a/tox.ini +++ b/tox.ini @@ -7,10 +7,8 @@ envlist = - py{36,py27}-checkqa [testenv] +extras = testing deps = - pytest>=3.6 - django-configurations==2.0 - pytest-xdist==1.15 {env:_PYTESTDJANGO_TOX_EXTRA_DEPS:} djmaster: https://github.com/django/django/archive/master.tar.gz