Skip to content

Commit 0bc7b19

Browse files
committed
[django-filter] Enable Django settings in stubtest
1 parent 63e9ab6 commit 0bc7b19

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
django-filter needs a Django settings module.
3+
This file is used in `tests/stubtest_third_party.py`.
4+
"""

stubs/django-filter/@tests/stubtest_allowlist.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Unhandled: these should be checked and fixed
12
django_filters.Filter.__init__
23
django_filters.FilterMethod
34
django_filters.FilterSet.base_filters
@@ -33,8 +34,3 @@ django_filters.views.MigrationNotice
3334
django_filters.views.RenameAttributesBase
3435
django_filters.widgets.BaseCSVWidget.surrogate
3536
django_filters.widgets.CSVWidget.__init__
36-
37-
# These fail due to DJANGO_SETTINGS_MODULE being unset
38-
django_filters.compat
39-
django_filters.conf
40-
django_filters.utils

tests/stubtest_third_party.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,16 @@ def run_stubtest(
107107
if platform_allowlist.exists():
108108
stubtest_cmd.extend(["--allowlist", str(platform_allowlist)])
109109

110-
# Perform some black magic in order to run stubtest inside uWSGI
111110
if dist_name == "uWSGI":
111+
# Perform some black magic in order to run stubtest inside uWSGI
112112
if not setup_uwsgi_stubtest_command(dist, venv_dir, stubtest_cmd):
113113
return False
114+
elif dist_name == "django-filter":
115+
# django-filter needs working Django settings
116+
stubtest_env["DJANGO_SETTINGS_MODULE"] = "django_settings"
117+
pythonpath = stubtest_env.get("PYTHONPATH")
118+
pythonpath = (pythonpath + os.pathsep if pythonpath else "") + str(dist / "@tests")
119+
stubtest_env["PYTHONPATH"] = pythonpath
114120

115121
try:
116122
subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True)

0 commit comments

Comments
 (0)