Skip to content

Commit

Permalink
[django-filter] Enable Django settings in stubtest
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr committed Oct 22, 2023
1 parent 63e9ab6 commit 0bc7b19
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions stubs/django-filter/@tests/django_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
django-filter needs a Django settings module.
This file is used in `tests/stubtest_third_party.py`.
"""
6 changes: 1 addition & 5 deletions stubs/django-filter/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Unhandled: these should be checked and fixed
django_filters.Filter.__init__
django_filters.FilterMethod
django_filters.FilterSet.base_filters
Expand Down Expand Up @@ -33,8 +34,3 @@ django_filters.views.MigrationNotice
django_filters.views.RenameAttributesBase
django_filters.widgets.BaseCSVWidget.surrogate
django_filters.widgets.CSVWidget.__init__

# These fail due to DJANGO_SETTINGS_MODULE being unset
django_filters.compat
django_filters.conf
django_filters.utils
8 changes: 7 additions & 1 deletion tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@ def run_stubtest(
if platform_allowlist.exists():
stubtest_cmd.extend(["--allowlist", str(platform_allowlist)])

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

try:
subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True)
Expand Down

0 comments on commit 0bc7b19

Please sign in to comment.