mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Add staticfiles handling to dist build
This commit is contained in:
parent
28262d17df
commit
7ca5e9097f
|
@ -2,6 +2,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import django
|
import django
|
||||||
|
from django.core import management
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
|
@ -9,6 +10,9 @@ def pytest_addoption(parser):
|
||||||
help='Remove package root directory from sys.path, ensuring that '
|
help='Remove package root directory from sys.path, ensuring that '
|
||||||
'rest_framework is imported from the installed site-packages. '
|
'rest_framework is imported from the installed site-packages. '
|
||||||
'Used for testing the distribution.')
|
'Used for testing the distribution.')
|
||||||
|
parser.addoption('--staticfiles', action='store_true', default=False,
|
||||||
|
help='Run tests with static files collection, using manifest '
|
||||||
|
'staticfiles storage. Used for testing the distribution.')
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
|
@ -82,4 +86,13 @@ def pytest_configure(config):
|
||||||
package_dir = os.path.join(os.getcwd(), 'rest_framework')
|
package_dir = os.path.join(os.getcwd(), 'rest_framework')
|
||||||
assert not rest_framework.__file__.startswith(package_dir)
|
assert not rest_framework.__file__.startswith(package_dir)
|
||||||
|
|
||||||
|
# Manifest storage will raise an exception if static files are not present (ie, a packaging failure).
|
||||||
|
if config.getoption('--staticfiles'):
|
||||||
|
import rest_framework
|
||||||
|
settings.STATIC_ROOT = os.path.join(os.path.dirname(rest_framework.__file__), 'static-root')
|
||||||
|
settings.STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
|
||||||
|
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
|
if config.getoption('--staticfiles'):
|
||||||
|
management.call_command('collectstatic', verbosity=0, interactive=False)
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -31,7 +31,7 @@ deps =
|
||||||
-rrequirements/requirements-optionals.txt
|
-rrequirements/requirements-optionals.txt
|
||||||
|
|
||||||
[testenv:dist]
|
[testenv:dist]
|
||||||
commands = ./runtests.py --fast {posargs} --no-pkgroot -rw
|
commands = ./runtests.py --fast {posargs} --no-pkgroot --staticfiles -rw
|
||||||
deps =
|
deps =
|
||||||
django
|
django
|
||||||
-rrequirements/requirements-testing.txt
|
-rrequirements/requirements-testing.txt
|
||||||
|
|
Loading…
Reference in New Issue
Block a user