django-cms icon indicating copy to clipboard operation
django-cms copied to clipboard

[docs] Tests breaking when running with Django 4 installation

Open mazulo opened this issue 3 years ago • 9 comments

Description

Hi folks, I just cloned the django-cms project to start digging into it. So the first thing I wanted to try was to running the tests. Following the instructions I installed the requirements for test_requirements/django-4.0.txt and when running the tests I got a few errors.

Steps to reproduce

  1. Clone the project
  2. Create a new env (I'm using version 3.8.10)
  3. Installed OS dependency with sudo apt install gettext
  4. Install the requirements: pip install -r test_requirements/django-4.0.txt
  5. Run the tests with python manage.py test
  6. See the errors showing up at the end

Expected behaviour

All the tests should pass

Actual behaviour

❯ python manage.py test
Found 1125 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
EE..................................................................................F.........................................................................................................
Publishing public drafts....
1.      *  home [1]
2.      *  página 1 [3]
3.      *  página 2 [5]

========================================

Total:     3
Published: 3
..................................................................................................................F........................................s...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
======================================================================
ERROR: cms.tests.test_docs (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: cms.tests.test_docs
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/mazulo/dev/projects/open-source/django-cms/cms/tests/test_docs.py", line 8, in <module>
    from sphinx.application import Sphinx
ModuleNotFoundError: No module named 'sphinx'


======================================================================
ERROR: cms.tests.test_i18n (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: cms.tests.test_i18n
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/mazulo/dev/projects/open-source/django-cms/cms/tests/test_i18n.py", line 5, in <module>
    from django.utils.translation import LANGUAGE_SESSION_KEY
ImportError: cannot import name 'LANGUAGE_SESSION_KEY' from 'django.utils.translation' (/home/mazulo/.virtualenvs/django_cms/lib/python3.8/site-packages/django/utils/translation/__init__.py)


======================================================================
FAIL: test_apphook_permissions_preserves_view_name (cms.tests.test_apphooks.ApphooksTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mazulo/.virtualenvs/django_cms/lib/python3.8/site-packages/django/test/utils.py", line 437, in inner
    return func(*args, **kwargs)
  File "/home/mazulo/dev/projects/open-source/django-cms/cms/tests/test_apphooks.py", line 318, in test_apphook_permissions_preserves_view_name
    self.assertEqual(match.func.__name__, view_name)
AssertionError: 'view' != 'ClassBasedView'
- view
+ ClassBasedView


======================================================================
FAIL: test_for_missing_migrations (cms.tests.test_migrations.MigrationTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mazulo/.virtualenvs/django_cms/lib/python3.8/site-packages/django/test/utils.py", line 437, in inner
    return func(*args, **kwargs)
  File "/home/mazulo/dev/projects/open-source/django-cms/cms/tests/test_migrations.py", line 28, in test_for_missing_migrations
    self.fail('There are missing migrations:\n {}'.format(output.getvalue()))
AssertionError: There are missing migrations:
 Migrations for 'djangocms_text_ckeditor':
  /home/mazulo/.virtualenvs/django_cms/lib/python3.8/site-packages/djangocms_text_ckeditor/migrations/0005_alter_text_cmsplugin_ptr.py
    - Alter field cmsplugin_ptr on text


----------------------------------------------------------------------
Ran 1125 tests in 95.096s

FAILED (failures=2, errors=2, skipped=1)

Screenshots

Additional information (CMS/Python/Django versions)

I'm using the following Ubuntu version in a WSL2 environment, with Windows 11:

❯ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal
  • Python version: 3.8.10
  • Django: 4.0.1
  • django-cms: 3.9.0

Do you want to help fix this issue?

  • [x] Yes, I want to help fix this issue and I will join #workgroup-pr-review on Slack to confirm with the community that a PR is welcome.
  • [ ] No, I only want to report the issue.

mazulo avatar Jun 17 '22 13:06 mazulo

django-cms 3.9 and 3.10 are not compatible with Django 4. pip should complain. When I upgrade django it says:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
django-cms 3.10.0 requires Django<4.0,>=2.2, but you have django 4.0.5 which is incompatible.

Note that django CMS 3.9 is outdated, 3.10 is the current stable version.

You might want to use a dependency manager like pip-tools or poetry.

MacLake avatar Jun 17 '22 13:06 MacLake

Thank you for quick answer @MacLake! I just upgraded the CMS version for 3.10. One thing that I noticed was that it also uninstalled the Django 4 version and installed Django-3.2.13 instead. There's one thing tho that I didn't understand (sorry if is a dumb question 😅): Why I got django-cms 3.9 when running pip install -r test_requirements/django-4.0.txt? When checking both files test_requirements/requirements_base.txt and test_requirements/django-4.0.txt I couldn't see any mention to django-cms. Is it a dependency of any of the other packages in those files?

Also in another note, after upgrading django-cms to 3.9 I still got the sphinx error. Should we add it to the test_requirements/requirements_base.txt? Right now it is only on the django-cms/docs/requirements.txt. I think it might be confusing to new contributors following the docs for tests and facing this issue. I'm totally open tho to better understand the project and its requirements structure 😄

❯ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
................................................................................................................................................................................................................
Publishing public drafts....
1.      *  home [1]
2.      *  página 1 [3]
3.      *  página 2 [5]

========================================

Total:     3
Published: 3
...........................................................................................................................................................s...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................E
======================================================================
ERROR: cms.tests.test_docs (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: cms.tests.test_docs
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/mazulo/dev/projects/open-source/django-cms/cms/tests/test_docs.py", line 8, in <module>
    from sphinx.application import Sphinx
ModuleNotFoundError: No module named 'sphinx'


----------------------------------------------------------------------
Ran 1144 tests in 98.222s

FAILED (errors=1, skipped=1)
Destroying test database for alias 'default'...

mazulo avatar Jun 17 '22 13:06 mazulo

@mazulo Can you do this? pip install -r docs/requirements.txt and try again?

It is also done when our CI runs the tests. https://github.com/django-cms/django-cms/blob/develop/.github/workflows/test.yml#L100

vinitkumar avatar Jun 17 '22 14:06 vinitkumar

Hey @vinitkumar thank you for your answer! I found this in the project, however I was still confused on why running the pip install -r test_requirements/django-4.0.txt as stated on the documentation for running tests would install an outdated version of django-cms. I was thinking, maybe we should add either sphinx==4.4.0 to the test_requirements/requirements_base.txt or -r docs/requirements.txt (the latter might be a little bit too much, not sure).

In the other hand, installing docs/requirements.txt solved the issue and the tests are passing! I mean, I noticed that when running with --parallel there's one failure (see the image below) image

mazulo avatar Jun 17 '22 14:06 mazulo

@mazulo You are right. Some of those parts definitely needs an update. I have not seen this test failure before as I never run the cms tests with --parallel. Could you report this failure.

vinitkumar avatar Jun 17 '22 14:06 vinitkumar

@vinitkumar sure! I'll open another issue about this failure.

mazulo avatar Jun 17 '22 14:06 mazulo

I just tried running the same test with --parallel but can't seem to reproduce it.

vinitkumar avatar Jun 17 '22 14:06 vinitkumar

Ok, so I believe we, as developers, should be setting up as close to the project test environment as we can.

The project test install the test requirements for each version they test, as well as the docs requirements;

https://github.com/django-cms/django-cms/blob/develop/.github/workflows/test.yml

The test in the cms test suite which needs Sphinx does a build of the docs to test it works. This is arguably unnecessary because there's another workflow which also does this. However, if it's doing a test of the docs build, it should have installed the same requirements that the docs use.

Now, with regards to the docs for setting up the project, I think we need a link to the compatibility table around this area because when setting up and environment, you should install the dango version compatible with.

I'd imagine the docs on writing & running tests take on the assumption that a developer is branching from develop and therefore each requirements file will be relevant. However if a past release is installed, there may be a requirements file present which has been created since the release was published - just like we have here with the django 4.0 requirements vs django-cms 3.9.

marksweb avatar Jun 18 '22 00:06 marksweb

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 16 '22 03:09 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 15 '22 10:12 stale[bot]

Fixed with release 3.11.1

fsbraun avatar Jan 11 '23 07:01 fsbraun