Pytest test suite randomly has errors on GitHub Actions without changes

Viewed 337

I have a problem with running my tests for a Python project inside Github Actions. Locally the test suite works like a charm and always succeeds. When it is run on Github Actions it succeeds in 1 out of 3 runs with no changes between the individual runs.

It seems as the creation of the Django app during the test doesn't always work as expected. Even though I try to assure it is created inside the pytest fixture.

@pytest.fixture
def installed_app(settings):
    app_name = f'test_theme_{str(uuid.uuid4()).replace("-", "_")}'
    app_path = Path(app_name)

    call_command("tailwind", "init", app_name)

    while not app_path.is_dir():
        time.sleep(1)

    settings.INSTALLED_APPS += [app_name]
    settings.TAILWIND_APP_NAME = app_name

    app_label = app_name.split(".")[-1]
    app_path = Path(apps.get_app_config(app_label).path)

    yield app_name, app_path

    if app_path.is_dir():
        shutil.rmtree(app_path)

I am confused what the reason is. I also tried it with Travis CI with the same problem. Any help is highly appreciated.

Here is the code of the tests.

Tests: https://github.com/oliverandrich/django-tailwind-postcss/blob/main/tests/tests.py Pytest fixture: https://github.com/oliverandrich/django-tailwind-postcss/blob/main/tests/conftest.py

============================= test session starts ==============================
9
platform linux -- Python 3.7.10, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
10
django: settings: tests.test_settings (from ini)
11
rootdir: /home/runner/work/django-tailwind-postcss/django-tailwind-postcss, configfile: pyproject.toml
12
plugins: django-4.1.0, cov-2.11.1
13
collected 11 items
14

15
tests/tests.py .....E
16

17
==================================== ERRORS ====================================
18
___________________ ERROR at setup of test_tailwind_install ____________________
19

20
settings = <pytest_django.fixtures.SettingsWrapper object at 0x7f074d653d90>
21

22
    @pytest.fixture
23
    def installed_app(settings):
24
        app_name = f'test_theme_{str(uuid.uuid4()).replace("-", "_")}'
25
        app_path = Path(app_name)
26
    
27
        call_command("tailwind", "init", app_name)
28
    
29
        while not app_path.is_dir():
30
            time.sleep(1)
31
    
32
>       settings.INSTALLED_APPS += [app_name]
33

34
tests/conftest.py:21: 
35
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
36
.venv/lib/python3.7/site-packages/pytest_django/fixtures.py:365: in __setattr__
37
    override.enable()
38
.venv/lib/python3.7/site-packages/django/test/utils.py:410: in enable
39
    apps.set_installed_apps(self.options['INSTALLED_APPS'])
40
.venv/lib/python3.7/site-packages/django/apps/registry.py:355: in set_installed_apps
41
    self.populate(installed)
42
.venv/lib/python3.7/site-packages/django/apps/registry.py:91: in populate
43
    app_config = AppConfig.create(entry)
44
.venv/lib/python3.7/site-packages/django/apps/config.py:90: in create
45
    module = import_module(entry)
46
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
47

48
name = 'test_theme_bd48d465_4482_40b9_a6e2_919cade2b69b', package = None
49

50
    def import_module(name, package=None):
51
        """Import a module.
52
    
53
        The 'package' argument is required when performing a relative import. It
54
        specifies the package to use as the anchor point from which to resolve the
55
        relative import to an absolute import.
56
    
57
        """
58
        level = 0
59
        if name.startswith('.'):
60
            if not package:
61
                msg = ("the 'package' argument is required to perform a relative "
62
                       "import for {!r}")
63
                raise TypeError(msg.format(name))
64
            for character in name:
65
                if character != '.':
66
                    break
67
                level += 1
68
>       return _bootstrap._gcd_import(name[level:], package, level)
69
E       ModuleNotFoundError: No module named 'test_theme_bd48d465_4482_40b9_a6e2_919cade2b69b'
70

71
/opt/hostedtoolcache/Python/3.7.10/x64/lib/python3.7/importlib/__init__.py:127: ModuleNotFoundError
72
---------------------------- Captured stdout setup -----------------------------
73
Tailwind application successfully created. Please add 'test_theme_bd48d465_4482_40b9_a6e2_919cade2b69b' to INSTALLED_APPS in settings.py.
74
=========================== short test summary info ============================
75
ERROR tests/tests.py::test_tailwind_install - ModuleNotFoundError: No module ...
76
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
77
========================== 5 passed, 1 error in 0.66s ==========================
0 Answers
Related