Skip to content

Commit 70ba0a1

Browse files
committed
allow runtests.py to discover tests in django_mongodb/tests
1 parent ed73791 commit 70ba0a1

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
17+
1618
try:
1719
import django
1820
except ImportError as e:
@@ -60,6 +62,9 @@
6062

6163
RUNTESTS_DIR = os.path.abspath(os.path.dirname(__file__))
6264

65+
MONGODB_TEST_DIR = Path(django_mongodb.__file__).parent.parent / "tests"
66+
sys.path.append(str(MONGODB_TEST_DIR))
67+
6368
TEMPLATE_DIR = os.path.join(RUNTESTS_DIR, "templates")
6469

6570
# Create a specific subdirectory for the duration of the test suite.
@@ -142,6 +147,21 @@ def get_test_modules(gis_enabled):
142147
test_module = dirname + "." + test_module
143148
yield test_module
144149

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

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

0 commit comments

Comments
 (0)