From a203c5d63d53c7eaedcea68e0e3923c444dda20d Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 22 Oct 2024 10:55:13 -0400 Subject: [PATCH] allow runtests.py to discover tests in django_mongodb/tests --- tests/runtests.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/runtests.py b/tests/runtests.py index 2eb7490170..535b53deee 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -13,6 +13,8 @@ import warnings from pathlib import Path +import django_mongodb + try: import django except ImportError as e: @@ -60,6 +62,9 @@ RUNTESTS_DIR = os.path.abspath(os.path.dirname(__file__)) +MONGODB_TEST_DIR = Path(django_mongodb.__file__).parent.parent / "tests" +sys.path.append(str(MONGODB_TEST_DIR)) + TEMPLATE_DIR = os.path.join(RUNTESTS_DIR, "templates") # Create a specific subdirectory for the duration of the test suite. @@ -142,6 +147,21 @@ def get_test_modules(gis_enabled): test_module = dirname + "." + test_module yield test_module + # Discover tests in django_mongodb/tests. + dirpath = os.path.join(MONGODB_TEST_DIR, dirname) + with os.scandir(dirpath) as entries: + for f in entries: + if ( + "." in f.name + or f.is_file() + or not os.path.exists(os.path.join(f.path, "__init__.py")) + ): + continue + test_module = f.name + if dirname: + test_module = dirname + "." + test_module + yield test_module + def get_label_module(label): """Return the top-level module part for a test label."""