From ecd9a33b17d0be52f98f1d7da74a56925c421585 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Sun, 10 Apr 2022 14:20:43 -0700 Subject: [PATCH] chore: Update test setup such that it runs from project root. Currently, the pytest-django is setup in a way that example_project is the root for the testing purposes and we specify paths like `../src` to the commands that need to run only _some_ tests compared to all. We also have to do things weirdly for docs and other kinds of commands that need to read Django settings etc. This change makes it such that we use project root as the reference directory when writing commands. This also modifies the appropriate commands in tox.ini to adapt to this change. Update documentation to reflect how the tests need to be run for specific tox environment and for specific test files. --- example_project/test_settings.py | 3 ++- pytest.ini | 3 ++- src/postorius/doc/development.rst | 44 ++++++++++++++++++++++++--------------- tox.ini | 8 +++---- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/example_project/test_settings.py b/example_project/test_settings.py index 3ab17d59..17252a48 100644 --- a/example_project/test_settings.py +++ b/example_project/test_settings.py @@ -20,8 +20,9 @@ Django test settings for postorius project. """ -from settings import * +from .settings import * +ROOT_URLCONF = 'example_project.urls' TESTING = True diff --git a/pytest.ini b/pytest.ini index 89a6df8b..faa57933 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] -addopts = --tb=short --create-db --reuse-db --ds=test_settings -s +addopts = --tb=short --create-db --reuse-db --ds=example_project.test_settings -s +pythonpath = . src \ No newline at end of file diff --git a/src/postorius/doc/development.rst b/src/postorius/doc/development.rst index 24dbe2dc..3450a409 100644 --- a/src/postorius/doc/development.rst +++ b/src/postorius/doc/development.rst @@ -58,25 +58,35 @@ dash: # List all currently configured envs: $ tox -l - py35-django111 - py35-django20 - py35-djangolatest - py36-django111 - py36-django20 - py36-djangolatest - py37-django111 - py37-django20 - py37-djangolatest - pep8 - - # Test Django 2.1 on Python3.7 only: - $ tox -e py37-django21 - - # Run only tests in ``test_address_activation``: - $ tox -- postorius.tests.test_address_activation + py36-django22 + py36-django31 + py36-django32 + py36-django-latest + py37-django22 + py37-django31 + py37-django32 + py37-django-latest + py38-django22 + py38-django31 + py38-django32 + py38-django-latest + py39-django22 + py39-django31 + py39-django32 + py39-django-latest + py310-django22 + py310-django31 + py310-django32 + py310-django-latest + + # Test Django 3.2 on Python3.7 only: + $ tox -e py37-django32 + + # Run only tests in ``test_address_activation.py``: + $ tox -e py37-django32-- src/postoriustests/test_address_activation.py # You get the idea... - $ tox -e py37-django21 -- postorius.tests.test_address_activation + $ tox -e py37-django32 -- postorius.tests.test_address_activation All test modules reside in the ``postorius/src/postorius/tests`` diff --git a/tox.ini b/tox.ini index 1b0aa7df..ad214273 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = py{36,37,38,39,310}-django{22,31,32,-latest},qa [testenv] usedevelop = True -changedir = {toxinidir}/example_project +changedir = {toxinidir} deps = mock beautifulsoup4 @@ -25,7 +25,7 @@ deps = django40: Django>=4.0,<4.1 django-latest: https://github.com/django/django/archive/main.tar.gz commands = - pytest {posargs:../src} + pytest {posargs:src/} setenv = LC_ALL = C.UTF-8 LANG = C.UTF-8 @@ -37,7 +37,7 @@ deps = Django>=3.2,<4.1 coverage commands = - coverage run -m pytest {posargs:../src/postorius} + coverage run -m pytest {posargs:src/} coverage html coverage report -m setenv = @@ -61,7 +61,7 @@ deps = whitelist_externals = mkdir commands= - sphinx-build -t html ../src/postorius/doc ../build/ + sphinx-build -t html src/postorius/doc build/ [flake8] basepython = python3 -- 2.11.4.GIT