Skip to content

Commit 2cb64e9

Browse files
authored
Merge pull request #631 from blueyed/remove-py
Remove py, add testing extras_require.
2 parents ab5821b + f2ea236 commit 2cb64e9

File tree

4 files changed

+41
-32
lines changed

4 files changed

+41
-32
lines changed

pytest_django/plugin.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import types
1313

14-
import py
14+
import pathlib
1515
import pytest
1616

1717
from .django_compat import is_django_unittest # noqa
@@ -88,13 +88,6 @@ def pytest_addoption(parser):
8888
type='bool', default=False)
8989

9090

91-
def _exists(path, ignore=EnvironmentError):
92-
try:
93-
return path.check()
94-
except ignore:
95-
return False
96-
97-
9891
PROJECT_FOUND = ('pytest-django found a Django project in %s '
9992
'(it contains manage.py) and added it to the Python path.\n'
10093
'If this is wrong, add "django_find_project = false" to '
@@ -121,21 +114,28 @@ def _handle_import_error(extra_message):
121114

122115

123116
def _add_django_project_to_path(args):
124-
args = [x for x in args if not str(x).startswith("-")]
125-
126-
if not args:
127-
args = [py.path.local()]
128-
129-
for arg in args:
130-
arg = py.path.local(arg)
131-
132-
for base in arg.parts(reverse=True):
133-
manage_py_try = base.join('manage.py')
134-
135-
if _exists(manage_py_try):
136-
sys.path.insert(0, str(base))
137-
return PROJECT_FOUND % base
117+
def is_django_project(path):
118+
return path.is_dir() and (path / 'manage.py').exists()
119+
120+
def find_django_path(args):
121+
args = [pathlib.Path(x) for x in args if not str(x).startswith("-")]
122+
args = [p for p in args if p.is_dir()]
123+
124+
if not args:
125+
args = [pathlib.Path.cwd()]
126+
127+
for arg in args:
128+
if is_django_project(arg):
129+
return arg
130+
for parent in arg.parents:
131+
if is_django_project(parent):
132+
return parent
133+
return None
138134

135+
project_dir = find_django_path(args)
136+
if project_dir:
137+
sys.path.insert(0, str(project_dir))
138+
return PROJECT_FOUND % project_dir
139139
return PROJECT_NOT_FOUND
140140

141141

setup.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,22 @@ def read(fname):
3030
long_description=read('README.rst'),
3131
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
3232
setup_requires=['setuptools_scm>=1.11.1'],
33-
install_requires=['pytest>=3.6'],
33+
install_requires=[
34+
'pytest>=3.6',
35+
'pathlib;python_version<"3.4"',
36+
],
3437
extras_require={
3538
'docs': [
3639
'sphinx',
3740
'sphinx_rtd_theme',
38-
]
41+
],
42+
'testing': [
43+
'pytest>=3.6',
44+
'Django',
45+
'django-configurations==2.0',
46+
'pytest-xdist==1.15',
47+
'six',
48+
],
3949
},
4050
classifiers=['Development Status :: 5 - Production/Stable',
4151
'Framework :: Django',

tests/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import shutil
33
from textwrap import dedent
44

5-
import py
5+
import pathlib
66
import pytest
7+
import six
78
from django.conf import settings
89

910
from pytest_django_test.db_helpers import DB_NAME, TEST_DB_NAME
1011

1112
pytest_plugins = 'pytester'
1213

13-
REPOSITORY_ROOT = py.path.local(__file__).join('..')
14+
REPOSITORY_ROOT = pathlib.Path(__file__).parent
1415

1516

1617
def pytest_configure(config):
@@ -99,12 +100,12 @@ def django_testdir(request, testdir, monkeypatch):
99100

100101
tpkg_path.ensure('__init__.py')
101102

102-
app_source = REPOSITORY_ROOT.dirpath('pytest_django_test/app')
103+
app_source = REPOSITORY_ROOT / '../pytest_django_test/app'
103104
test_app_path = tpkg_path.join('app')
104105

105106
# Copy the test app to make it available in the new test run
106-
shutil.copytree(py.builtin._totext(app_source),
107-
py.builtin._totext(test_app_path))
107+
shutil.copytree(six.text_type(app_source),
108+
six.text_type(test_app_path))
108109
tpkg_path.join("the_settings.py").write(test_settings)
109110

110111
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'tpkg.the_settings')

tox.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ envlist =
77
py{36,py27}-checkqa
88

99
[testenv]
10+
extras = testing
1011
deps =
11-
pytest>=3.6
12-
django-configurations==2.0
13-
pytest-xdist==1.15
1412
{env:_PYTESTDJANGO_TOX_EXTRA_DEPS:}
1513

1614
djmaster: https://github.com/django/django/archive/master.tar.gz

0 commit comments

Comments
 (0)