diff --git a/.travis.yml b/.travis.yml index c5a15140d..f503eb5e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,19 @@ matrix: - { python: "3.6", env: DJANGO=2.0 } - { python: "2.7", env: TOXENV=lint } - { python: "2.7", env: TOXENV=docs } - - python: "2.7" + + - python: "3.6" + env: TOXENV=dist + script: + - python setup.py bdist_wheel + - tox --installpkg ./dist/djangorestframework-*.whl + - tox # test sdist + + - python: "3.6" env: TOXENV=readme addons: apt_packages: pandoc + exclude: - { python: "2.7", env: DJANGO=master } - { python: "2.7", env: DJANGO=2.0 } diff --git a/runtests.py b/runtests.py index 5e8460c85..a8f818ad7 100755 --- a/runtests.py +++ b/runtests.py @@ -16,8 +16,6 @@ FLAKE8_ARGS = ['rest_framework', 'tests'] ISORT_ARGS = ['--recursive', '--check-only', '-o' 'uritemplate', '-p', 'tests', 'rest_framework', 'tests'] -sys.path.append(os.path.dirname(__file__)) - def exit_on_failure(ret, message=None): if ret: @@ -84,6 +82,20 @@ if __name__ == "__main__": run_flake8 = 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: pytest_args = sys.argv[1:] first_arg = pytest_args[0] diff --git a/tox.ini b/tox.ini index e2d7aa448..f04e6ba93 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ envlist = {py27,py34,py35,py36}-django111, {py34,py35,py36}-django20, {py35,py36}-djangomaster, - lint,docs,readme, + dist,lint,docs,readme, [travis:env] DJANGO = @@ -18,6 +18,7 @@ DJANGO = [testenv] commands = ./runtests.py --fast {posargs} --coverage -rw +envdir = {toxworkdir}/venvs/{envname} setenv = PYTHONDONTWRITEBYTECODE=1 PYTHONWARNINGS=once @@ -29,6 +30,13 @@ deps = -rrequirements/requirements-testing.txt -rrequirements/requirements-optionals.txt +[testenv:dist] +commands = ./runtests.py --fast {posargs} --no-pkgroot -rw +deps = + django + -rrequirements/requirements-testing.txt + -rrequirements/requirements-optionals.txt + [testenv:lint] basepython = python2.7 commands = ./runtests.py --lintonly