[CI] Cog Unit Tests are consistently failing
quachtridat opened this issue · 0 comments
Summary
CI has been consistently failing recently with log lines like
AttributeError: 'async_generator' object has no attribute 'foo'
Failed runs
- https://github.com/Injabie3/lui-cogs-v3/actions/runs/4587186975
- https://github.com/Injabie3/lui-cogs-v3/actions/runs/4604477459
- https://github.com/Injabie3/lui-cogs-v3/actions/runs/4625510253
- https://github.com/Injabie3/lui-cogs-v3/actions/runs/4644301875
Root cause
This is caused by pytest-asyncio
's strict test discovery mode.
When the strict mode is on, async fixtures need to be defined with decorator @pytest_asyncio.fixture()
to be picked up by pytest-asyncio
(and function correctly in our cases). Fixtures decorated with @pytest.fixture()
will not be recognized.
For SFUAnime/Ren, this line of code tweaks pytest-asyncio
's test discovery mode by making in auto
instead of strict
(the default value), and thus async fixtures decorated with @pytest.fixture()
continue to work normally. This is not the case with the current repo (Injabie3/lui-cogs-v3).
How it was found out
There is a difference in the asyncio
mode between this workflow log line from an unsuccessful run in Injabie3/lui-cogs-v3 and this workflow log line from a successful run in SFUAnime/Ren.
Proposed fix
To resolve, we need to:
- Use
pytest_asyncio.fixture()
instead ofpytest.fixture()
, or - Have a pytest config file (e.g.,
pytest.ini
) and setasync_mode
toauto
.
The former is preferred simply because we don't need an additional file to tweak this behavior of pytest-asyncio
.