Skip to content

Commit 30fad7b

Browse files
committed
Use py.test for testing
1 parent 9d674e4 commit 30fad7b

File tree

7 files changed

+74
-95
lines changed

7 files changed

+74
-95
lines changed

docs/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ We require features to be backed by a unit test.
1313
This way, we can test *django-polymorphic* against new Django versions.
1414
To run the included test suite, execute::
1515

16-
./runtests.py
16+
py.test
1717

1818
To test support for multiple Python and Django versions, run tox from the repository root::
1919

manage.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This helps pytest-django locate the project.
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "polymorphic_test_settings")
7+
from django.core.management import execute_from_command_line
8+
9+
execute_from_command_line(sys.argv)

polymorphic/tests/test_contrib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest import TestCase
1+
from django.test import TestCase
22

33
from polymorphic.contrib.guardian import get_polymorphic_base_content_type
44
from polymorphic.tests.models import Model2D, PlainC

polymorphic_test_settings.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import dj_database_url
2+
3+
DEBUG = False
4+
DATABASES = {
5+
"default": dj_database_url.config(
6+
env="PRIMARY_DATABASE",
7+
default="sqlite://:memory:",
8+
),
9+
"secondary": dj_database_url.config(
10+
env="SECONDARY_DATABASE",
11+
default="sqlite://:memory:",
12+
),
13+
}
14+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
15+
INSTALLED_APPS = (
16+
"django.contrib.auth",
17+
"django.contrib.contenttypes",
18+
"django.contrib.messages",
19+
"django.contrib.sessions",
20+
"django.contrib.sites",
21+
"django.contrib.admin",
22+
"polymorphic",
23+
"polymorphic.tests",
24+
)
25+
MIDDLEWARE = (
26+
"django.middleware.common.CommonMiddleware",
27+
"django.contrib.sessions.middleware.SessionMiddleware",
28+
"django.middleware.csrf.CsrfViewMiddleware",
29+
"django.contrib.auth.middleware.AuthenticationMiddleware",
30+
"django.contrib.messages.middleware.MessageMiddleware",
31+
)
32+
SITE_ID = 3
33+
TEMPLATES = [
34+
{
35+
"BACKEND": "django.template.backends.django.DjangoTemplates",
36+
"DIRS": (),
37+
"OPTIONS": {
38+
"loaders": (
39+
"django.template.loaders.filesystem.Loader",
40+
"django.template.loaders.app_directories.Loader",
41+
),
42+
"context_processors": (
43+
"django.template.context_processors.debug",
44+
"django.template.context_processors.i18n",
45+
"django.template.context_processors.media",
46+
"django.template.context_processors.request",
47+
"django.template.context_processors.static",
48+
"django.contrib.messages.context_processors.messages",
49+
"django.contrib.auth.context_processors.auth",
50+
),
51+
},
52+
}
53+
]
54+
POLYMORPHIC_TEST_SWAPPABLE = "polymorphic.swappedmodel"
55+
ROOT_URLCONF = None
56+
SECRET_KEY = "supersecret"

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ select = [
3333
"F841",
3434
"I",
3535
]
36+
37+
[tool.pytest.ini_options]
38+
DJANGO_SETTINGS_MODULE = "polymorphic_test_settings"

runtests.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ setenv =
1212
postgres: DEFAULT_DATABASE = postgres:///default
1313
postgres: SECONDARY_DATABASE = postgres:///secondary
1414
deps =
15-
coverage
15+
pytest
16+
pytest-cov
17+
pytest-django
1618
dj-database-url
1719
django32: Django ~= 3.2
1820
django40: Django ~= 4.0
@@ -22,7 +24,7 @@ deps =
2224
djangomain: https://github.com/django/django/archive/main.tar.gz
2325
postgres: psycopg2
2426
commands =
25-
coverage run --source polymorphic runtests.py
27+
py.test --cov --cov-report=term-missing --cov-report=xml .
2628

2729
[testenv:docs]
2830
deps =

0 commit comments

Comments
 (0)