Skip to content

Commit cd064d2

Browse files
committed
allow runtests.py to discover tests in django_mongodb/tests
1 parent 5386c3a commit cd064d2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/runtests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import warnings
1414
from pathlib import Path
1515

16+
import django_mongodb_backend
17+
1618
try:
1719
import django
1820
except ImportError as e:
@@ -57,6 +59,9 @@
5759

5860
RUNTESTS_DIR = os.path.abspath(os.path.dirname(__file__))
5961

62+
MONGODB_TEST_DIR = Path(django_mongodb_backend.__file__).parent.parent / "tests"
63+
sys.path.append(str(MONGODB_TEST_DIR))
64+
6065
TEMPLATE_DIR = os.path.join(RUNTESTS_DIR, "templates")
6166

6267
# Create a specific subdirectory for the duration of the test suite.
@@ -139,6 +144,21 @@ def get_test_modules(gis_enabled):
139144
test_module = dirname + "." + test_module
140145
yield test_module
141146

147+
# Discover tests in django_mongodb_backend/tests.
148+
dirpath = os.path.join(MONGODB_TEST_DIR, dirname)
149+
with os.scandir(dirpath) as entries:
150+
for f in entries:
151+
if (
152+
"." in f.name
153+
or f.is_file()
154+
or not os.path.exists(os.path.join(f.path, "__init__.py"))
155+
):
156+
continue
157+
test_module = f.name
158+
if dirname:
159+
test_module = dirname + "." + test_module
160+
yield test_module
161+
142162

143163
def get_label_module(label):
144164
"""Return the top-level module part for a test label."""

0 commit comments

Comments
 (0)