Gitlab CI-CD Pipeline throws pytest Assertion error

We have a python repo hosted on Gitlab.com with a pipeline defined that builds a Python 3.7 docker image, installs dependencies from requirements file(s) then executes our suite of pytest tests. Up to the last merged commit on Wednesday January 12th 2022, this was working, however now the pipeline throws an error immediately at the pytest statement, before executing any tests:

image: "python:3.7"

before_script:
    - python --version
    - pip install --use-deprecated=legacy-resolver -r requirements/dev.txt
    - pip install --use-deprecated=legacy-resolver -r requirements/ml.txt

stages:
    - test

test:
    script:
        - DEBUG=true pytest

Now, even running the pipeline on the last merged commit throws an error. The ci.yml has not changed, there haven’t been changes to the tests, the version of pytest we install is unchanged and running the test suite locally poses no issues.

The CI pipeline gives the following error:

File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.7/site-packages/pytest_asyncio/plugin.py", line 57, in pytest_addoption
    default="legacy",
  File "/usr/local/lib/python3.7/site-packages/_pytest/config/argparsing.py", line 178, in addini
    assert type in (None, "pathlist", "args", "linelist", "bool")
AssertionError
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

Normally, there would at least be preamble showing pytest finding and executing out suite of tests.

The only similar lead I could find via search engines was: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000363799-Empty-test-suite-Exit-code-1 and in that case, the user had to change versions of IntelliJ to resolve their issue.

So far I’ve unsuccessfully tried:

  • Adding a statement to install and activate a python virtual environment “pre-script”
  • Explicitly specifying the test folder (DEBUG=true pytest tests/ )

Appreciate any help possible!

I had the same problem. I suppose it’s a bug in pytest_asyncio 0.17. Try to change version of pytest_asyncio from 0.17.* to 0.16.*

1 Like

Amazing! Thank you it worked for me as well.

Coming back from the weekend, I saw that another engineer on my team wound up upgrading our whole pytest version to fix the pipeline but your suggestion isolates the specific cause of the strange behaviour: we didn’t specify a version for pytest_asyncio in our requirements file so that changed on us unnoticed.

Thank you for sharing your solution!