Failed: running tests while setting up django for fist time in local for contributions

Hi everyone!

I’m pretty new here and I am trying to set up Django in my local environment for contributions.
I am following the : Writing your first patch for Django | Django documentation | Django to get myself familiar with on how to get started.

I am stuck on this issue for a while now, where some of the tests are failing without even doing any changes in the code base, I tried to look for solutions but couldn’t find anything helpful.

The error:

FAIL: test_readonly_root (file_uploads.tests.DirectoryCreationTests)
Permission errors are not swallowed
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 591, in run
    self._callTestMethod(testMethod)
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
    method()
  File "/mnt/c/Users/DELL/Documents/django-dev/django/django/test/utils.py", line 443, in inner
    return func(*args, **kwargs)
  File "/mnt/c/Users/DELL/Documents/django-dev/django/tests/file_uploads/tests.py", line 820, in test_readonly_root
    with self.assertRaises(PermissionError):
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 226, in __exit__
    self._raiseFailure("{} not raised".format(exc_name))
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 163, in _raiseFailure
    raise self.test_case.failureException(msg)
AssertionError: PermissionError not raised

======================================================================
FAIL: test_honor_umask (admin_scripts.tests.StartProject) [settings.py]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 498, in subTest
    yield
  File "/mnt/c/Users/DELL/Documents/django-dev/django/tests/admin_scripts/tests.py", line 2828, in test_honor_umask
    self.assertEqual(
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 837, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 830, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 448 != 384

======================================================================
FAIL: test_permissions_error (template_tests.test_loaders.FileSystemLoaderTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 591, in run
    self._callTestMethod(testMethod)
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
    method()
  File "/mnt/c/Users/DELL/Documents/django-dev/django/tests/template_tests/test_loaders.py", line 226, in test_permissions_error
    with self.assertRaisesMessage(PermissionError, "Permission denied"):
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/contextlib.py", line 142, in __exit__
    next(self.gen)
  File "/mnt/c/Users/DELL/Documents/django-dev/django/django/test/testcases.py", line 739, in _assert_raises_or_warns_cm
    with func(expected_exception) as cm:
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 226, in __exit__
    self._raiseFailure("{} not raised".format(exc_name))
  File "/root/.pyenv/versions/3.10.0/lib/python3.10/unittest/case.py", line 163, in _raiseFailure
    raise self.test_case.failureException(msg)
AssertionError: PermissionError not raised

----------------------------------------------------------------------
Ran 16549 tests in 352.284s

FAILED (failures=3, skipped=1330, expected failures=5)

I would like very much to continue and explore Django, but can’t find any answer to this problem.
Can anyone please help me with figuring out what can be the issue behind this and how I can resolve it?

Thank you very much

Hmmm ok so maybe for the permission ones, if you update the test to not have the with statement trying to catch the permission error it might be that a different type of error is being raised and „swallowed“ or no error is raised. Be good to see what’s happening instead of the permission error :+1:

1 Like

It could be any number of things specific to your setup :man_shrugging:

On large projects like this I usually expect a handful of tests to fail for my specific environment. I haven’t run the full suite locally for a while but iirc there were some failures unrelated to what I was working on.

It may be helpful (even as just a nice learning exercise) for you to dive into the test failures. There’s always the chance there are some issues that need to be resolved which the team needs to know about.

Personally I wouldn’t worry about it – the important thing is that they’re passing on the established environments in CI. :blush:

2 Likes

Thanks, @sarahboyce and @shangxiao for your suggestions.
And Yes as you suggested, it was some permission issue related to my environment, as earlier I was using WSL in Windows for setting up and running the tests and because of some permission issue with WSL it was giving those errors, I ran it on Windows now and it worked fine. :partying_face:

1 Like