summary refs log tree commit diff
diff options
context:
space:
mode:
authorMartin Weinelt <hexa@darmstadt.ccc.de>2022-06-10 23:07:30 +0200
committerMartin Weinelt <hexa@darmstadt.ccc.de>2023-04-04 03:23:56 +0200
commit7109d10aab33a36571737977ef48ac99c050453b (patch)
treec5d70acd31ad97d80febf8e11a09d9b91b910317
parent4a269e1afa72e97aeef00b3eae729a61d31a1180 (diff)
downloadnixpkgs-7109d10aab33a36571737977ef48ac99c050453b.tar
nixpkgs-7109d10aab33a36571737977ef48ac99c050453b.tar.gz
nixpkgs-7109d10aab33a36571737977ef48ac99c050453b.tar.bz2
nixpkgs-7109d10aab33a36571737977ef48ac99c050453b.tar.lz
nixpkgs-7109d10aab33a36571737977ef48ac99c050453b.tar.xz
nixpkgs-7109d10aab33a36571737977ef48ac99c050453b.tar.zst
nixpkgs-7109d10aab33a36571737977ef48ac99c050453b.zip
python310Packages.django_4: enable tests on linux
Tests still fail on darwin because of missing timezone information, no
idea how to resolve that. TZDIR does work on Linux.
-rw-r--r--pkgs/development/python-modules/django/4.nix35
-rw-r--r--pkgs/development/python-modules/django/django_4_tests.patch51
2 files changed, 77 insertions, 9 deletions
diff --git a/pkgs/development/python-modules/django/4.nix b/pkgs/development/python-modules/django/4.nix
index 6ec2e8c9067..26b7391c51e 100644
--- a/pkgs/development/python-modules/django/4.nix
+++ b/pkgs/development/python-modules/django/4.nix
@@ -26,15 +26,14 @@
 , docutils
 , geoip2
 , jinja2
-, python-memcached
 , numpy
 , pillow
 , pylibmc
 , pymemcache
 , python
-, pytz
 , pywatchman
 , pyyaml
+, pytz
 , redis
 , selenium
 , tblib
@@ -58,6 +57,9 @@ buildPythonPackage rec {
       src = ./django_4_set_zoneinfo_dir.patch;
       zoneinfo = tzdata + "/share/zoneinfo";
     })
+    # make sure the tests don't remove packages from our pythonpath
+    # and disable failing tests
+    ./django_4_tests.patch
   ] ++ lib.optionals withGdal [
     (substituteAll {
       src = ./django_4_set_geos_gdal_lib.patch;
@@ -67,6 +69,11 @@ buildPythonPackage rec {
     })
   ];
 
+  postPatch = ''
+    substituteInPlace tests/utils_tests/test_autoreload.py \
+      --replace "/usr/bin/python" "${python.interpreter}"
+  '';
+
   nativeBuildInputs = [
     setuptools
   ];
@@ -85,37 +92,47 @@ buildPythonPackage rec {
     ];
   };
 
-  # Fails to import asgiref in ~200 tests
-  # ModuleNotFoundError: No module named 'asgiref'
-  doCheck = false;
-
   nativeCheckInputs = [
+    # tests/requirements/py3.txt
     aiosmtpd
     docutils
     geoip2
     jinja2
-    python-memcached
     numpy
     pillow
     pylibmc
     pymemcache
-    pytz
     pywatchman
     pyyaml
+    pytz
     redis
     selenium
     tblib
     tzdata
   ] ++ lib.flatten (lib.attrValues passthru.optional-dependencies);
 
+  doCheck = !stdenv.isDarwin;
+
+  preCheck = ''
+    # make sure the installed library gets imported
+    rm -rf django
+
+    # provide timezone data, works only on linux
+    export TZDIR=${tzdata}/${python.sitePackages}/tzdata/zoneinfo
+  '';
+
   checkPhase = ''
     runHook preCheck
 
-    ${python.interpreter} tests/runtests.py
+    pushd tests
+    ${python.interpreter} runtests.py --settings=test_sqlite
+    popd
 
     runHook postCheck
   '';
 
+  __darwinAllowLocalNetworking = true;
+
   meta = with lib; {
     changelog = "https://docs.djangoproject.com/en/${lib.versions.majorMinor version}/releases/${version}/";
     description = "A high-level Python Web framework that encourages rapid development and clean, pragmatic design.";
diff --git a/pkgs/development/python-modules/django/django_4_tests.patch b/pkgs/development/python-modules/django/django_4_tests.patch
new file mode 100644
index 00000000000..689e1ed652a
--- /dev/null
+++ b/pkgs/development/python-modules/django/django_4_tests.patch
@@ -0,0 +1,51 @@
+diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
+index 6d67c2931a..0c1f407f88 100644
+--- a/tests/admin_scripts/tests.py
++++ b/tests/admin_scripts/tests.py
+@@ -127,6 +127,7 @@ class AdminScriptTestCase(SimpleTestCase):
+             del test_environ["DJANGO_SETTINGS_MODULE"]
+         python_path = [base_dir, django_dir, tests_dir]
+         python_path.extend(ext_backend_base_dirs)
++        python_path.extend(sys.path)
+         test_environ["PYTHONPATH"] = os.pathsep.join(python_path)
+         test_environ["PYTHONWARNINGS"] = ""
+ 
+diff --git a/tests/auth_tests/test_hashers.py b/tests/auth_tests/test_hashers.py
+index 36f22d5f09..6cc6888980 100644
+--- a/tests/auth_tests/test_hashers.py
++++ b/tests/auth_tests/test_hashers.py
+@@ -1,4 +1,4 @@
+-from unittest import mock, skipUnless
++from unittest import mock, skipUnless, skip
+ 
+ from django.conf.global_settings import PASSWORD_HASHERS
+ from django.contrib.auth.hashers import (
+@@ -241,6 +241,7 @@ class TestUtilsHashPass(SimpleTestCase):
+ 
+     @ignore_warnings(category=RemovedInDjango50Warning)
+     @skipUnless(crypt, "no crypt module to generate password.")
++    @skip("Legacy crypt algorithms are unsupported in nixpkgs")
+     @override_settings(
+         PASSWORD_HASHERS=["django.contrib.auth.hashers.CryptPasswordHasher"]
+     )
+diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
+index 62cbffbee9..2f0ec718f8 100644
+--- a/tests/settings_tests/tests.py
++++ b/tests/settings_tests/tests.py
+@@ -2,7 +2,7 @@ import os
+ import sys
+ import unittest
+ from types import ModuleType, SimpleNamespace
+-from unittest import mock
++from unittest import mock, skip
+ 
+ from django.conf import (
+     ENVIRONMENT_VARIABLE,
+@@ -342,6 +342,7 @@ class SettingsTests(SimpleTestCase):
+             getattr(s, "foo")
+ 
+     @requires_tz_support
++    @skip("Assertion fails, exception does not get raised")
+     @mock.patch("django.conf.global_settings.TIME_ZONE", "test")
+     def test_incorrect_timezone(self):
+         with self.assertRaisesMessage(ValueError, "Incorrect timezone setting: test"):