Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tests failling after django and python upgrade

I’ve upgraded Django from 4.0.5 to 4.1.6 and python from 3.9 to 3.11

I’ve also upgraded dependencies:

   pip==23.0
   pytest==7.2.1
   pytest-django==4.5.2
   coverage==7.1.0
   pytest-cov==4.0.0
   pylint==2.16.2
   mock==5.0.1

These are my logs:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

django-admin test
Traceback (most recent call last):
  File "/usr/local/bin/django-admin", line 8, in <module>
    sys.exit(execute_from_command_line())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/test.py", line 24, in run_from_argv
    super().run_from_argv(argv)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 394, in run_from_argv
    parser = self.create_parser(argv[0], argv[1])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 357, in create_parser
    self.add_arguments(parser)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/test.py", line 54, in add_arguments
    test_runner_class = get_runner(settings, self.test_runner)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/test/utils.py", line 394, in get_runner
    test_module = __import__(test_module_name, {}, {}, test_path[-1])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django_coverage/coverage_runner.py", line 31, in <module>
    from django.db.models import get_app, get_apps
ImportError: cannot import name 'get_app' from 'django.db.models' (/usr/local/lib/python3.11/site-packages/django/db/models/__init__.py)

>Solution :

The error message suggests that there is an import error in the file /usr/local/lib/python3.11/site-packages/django_coverage/coverage_runner.py. Specifically, it seems to be caused by an attempt to import the function ‘get_app’ from ‘django.db.models’, which is no longer available in Django 4.1.

Instead of ‘get_app’, you can use ‘apps.get_app_config’ to get the configuration of a specific app. You can also use ‘apps.get_app_configs’ to get the configurations of all installed apps.

You will need to update the code in /usr/local/lib/python3.11/site-packages/django_coverage/coverage_runner.py to use the new method of getting app configurations.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading