mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Move '--no-pkgroot' handling to conftest
This commit is contained in:
parent
745dc798f1
commit
28262d17df
15
runtests.py
15
runtests.py
|
@ -1,7 +1,6 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -82,20 +81,6 @@ if __name__ == "__main__":
|
||||||
run_flake8 = False
|
run_flake8 = False
|
||||||
run_isort = False
|
run_isort = False
|
||||||
|
|
||||||
try:
|
|
||||||
# Remove the package root directory from `sys.path`, ensuring that rest_framework
|
|
||||||
# is imported from the installed site packages. Used for testing the distribution
|
|
||||||
sys.argv.remove('--no-pkgroot')
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
sys.path.pop(0)
|
|
||||||
|
|
||||||
# import rest_framework before pytest re-adds the package root directory.
|
|
||||||
import rest_framework
|
|
||||||
package_dir = os.path.join(os.getcwd(), 'rest_framework')
|
|
||||||
assert not rest_framework.__file__.startswith(package_dir)
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
pytest_args = sys.argv[1:]
|
pytest_args = sys.argv[1:]
|
||||||
first_arg = pytest_args[0]
|
first_arg = pytest_args[0]
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import django
|
import django
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure():
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption('--no-pkgroot', action='store_true', default=False,
|
||||||
|
help='Remove package root directory from sys.path, ensuring that '
|
||||||
|
'rest_framework is imported from the installed site-packages. '
|
||||||
|
'Used for testing the distribution.')
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_configure(config):
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
settings.configure(
|
settings.configure(
|
||||||
|
@ -64,4 +74,12 @@ def pytest_configure():
|
||||||
'guardian',
|
'guardian',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if config.getoption('--no-pkgroot'):
|
||||||
|
sys.path.pop(0)
|
||||||
|
|
||||||
|
# import rest_framework before pytest re-adds the package root directory.
|
||||||
|
import rest_framework
|
||||||
|
package_dir = os.path.join(os.getcwd(), 'rest_framework')
|
||||||
|
assert not rest_framework.__file__.startswith(package_dir)
|
||||||
|
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user