Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest async fixture seems not work on linux-py3.7 #386

Closed
chaokunyang opened this issue Jul 18, 2022 · 5 comments
Closed

pytest async fixture seems not work on linux-py3.7 #386

chaokunyang opened this issue Jul 18, 2022 · 5 comments

Comments

@chaokunyang
Copy link

chaokunyang commented Jul 18, 2022

pytest async fixture seems not work on linux-py3.7 seems not work on linux python3.7

Code

import pytest

@pytest.mark.parametrize(indirect=True)
@pytest.fixture
async def async_fixture1(request):
    yield "async_fixture1:value"


@pytest.mark.asyncio
async def test_async_fixture1(async_fixture1):
    print(async_fixture1)
    assert async_fixture1 == "async_fixture1:value"

Stacktrace

$ pytest t.py 
================================================================================================ test session starts =================================================================================================
platform linux -- Python 3.7.11, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/jenkins/agent/aci, configfile: setup.cfg
plugins: flaky-3.7.0, timeout-2.1.0, cov-3.0.0, asyncio-0.19.0, forked-1.4.0
asyncio: mode=strict
collected 1 item                                                                                                                                                                                                     

t.py F                                                                                                                                                                                                         [100%]

====================================================================================================== FAILURES ======================================================================================================
________________________________________________________________________________________________ test_async_fixture1 _________________________________________________________________________________________________

async_fixture1 = <async_generator object async_fixture1 at 0x7fa846418950>

    @pytest.mark.asyncio
    async def test_async_fixture1(async_fixture1):
        print(async_fixture1)
>       assert async_fixture1 == "async_fixture1:value"
E       AssertionError: assert <async_generator object async_fixture1 at 0x7fa846418950> == 'async_fixture1:value'

t.py:12: AssertionError
------------------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------------------
<async_generator object async_fixture1 at 0x7fa846418950>
============================================================================================== short test summary info ===============================================================================================
FAILED t.py::test_async_fixture1 - AssertionError: assert <async_generator object async_fixture1 at 0x7fa846418950> == 'async_fixture1:value'
================================================================================================= 1 failed in 0.05s =============================

System info

OS: fedora
Python version: 3.7.11
Pip list:

Package                  Version                      Editable project location
------------------------ ---------------------------- -------------------------
aiohttp                  3.7.0
aiohttp-cors             0.7.0
aioredis                 1.3.1
aliyun-python-sdk-core   2.13.36
aliyun-python-sdk-kms    2.15.0
async-timeout            3.0.1
attrs                    21.4.0
black                    22.6.0
blessings                1.7
boto3                    1.24.31
botocore                 1.27.31
cachetools               5.2.0
certifi                  2022.6.15
cffi                     1.15.1
chardet                  3.0.4
charset-normalizer       2.1.0
click                    8.0.4
cloudpickle              2.1.0
cmake                    3.21.4
colorama                 0.4.5
coverage                 6.4.2
crcmod                   1.7
cryptography             3.4.8
Cython                   0.29.30
defusedxml               0.7.1
distlib                  0.3.5
filelock                 3.7.1
flake8                   4.0.1
flaky                    3.7.0
google-api-core          2.8.2
google-auth              2.9.1
googleapis-common-protos 1.56.4
gpustat                  0.6.0
greenlet                 1.1.2
grpcio                   1.47.0
hiredis                  2.0.0
idna                     3.3
importlib-metadata       4.12.0
importlib-resources      5.8.0
iniconfig                1.1.1
Jinja2                   3.1.2
jmespath                 0.10.0
joblib                   1.1.0
jsonschema               4.7.2
lz4                      4.0.1
MarkupSafe               2.1.1
mccabe                   0.6.1
mock                     4.0.3
moto                     3.1.16
msgpack                  1.0.4
multidict                6.0.2
mypy-extensions          0.4.3
numexpr                  2.8.3
numpy                    1.17.3
nvidia-ml-py3            7.352.0
opencensus               0.10.0
opencensus-context       0.1.2
oss2                     2.15.0
packaging                21.3
pandas                   1.3.0
pathspec                 0.9.0
pickle5                  0.0.12
Pillow                   9.2.0
pip                      22.1.2
platformdirs             2.5.2
pluggy                   1.0.0
prometheus-client        0.11.0
protobuf                 3.19.4
psutil                   5.9.1
py                       1.11.0
py-cpuinfo               6.0.0
py-spy                   0.3.12
pyarrow                  4.0.1
pyasn1                   0.4.8
pyasn1-modules           0.2.8
pycodestyle              2.8.0
pycparser                2.21
pycryptodome             3.15.0
pydantic                 1.9.1
pyflakes                 2.4.0
pymars                   0+untagged.10.gf04ab4f.dirty /home/jenkins/agent/aci
pyparsing                3.0.9
pyrsistent               0.18.1
pytest                   7.1.2
pytest-asyncio           0.19.0
pytest-cov               3.0.0
pytest-forked            1.4.0
pytest-timeout           2.1.0
python-dateutil          2.8.2
pytz                     2022.1
PyYAML                   6.0
ray                      2.0.0.dev0
ray-actor-optimizer      0.1.0
redis                    3.5.3
requests                 2.28.1
responses                0.21.0
rsa                      4.8
s3transfer               0.6.0
scikit-learn             1.0.2
scipy                    1.5.0
setproctitle             1.2.3
setuptools               63.2.0
shared-memory38          0.1.2
six                      1.16.0
sklearn                  0.0
SQLAlchemy               1.4.39
testfixtures             6.18.3
threadpoolctl            3.1.0
tomli                    2.0.1
tornado                  6.2
tqdm                     4.64.0
typed-ast                1.5.4
typing_extensions        4.3.0
urllib3                  1.26.10
uvloop                   0.16.0
virtualenv               20.15.1
Werkzeug                 2.1.2
wheel                    0.37.1
xmltodict                0.13.0
yarl                     1.7.2
zipp                     3.8.1
@eirnym
Copy link

eirnym commented Jul 18, 2022

Could you please share your is details to reproduce the issue. Also it's important to know what it means "not working"

@chaokunyang
Copy link
Author

Thanks for your quick reply, I added the pip list info, is there other details I can add? The test script work on my mac, but failed at linux.

@chaokunyang
Copy link
Author

chaokunyang commented Jul 18, 2022

Seems it's caused by pytest-asyncio==0.19, aftger downgrade it to 0.18, everything works fine

@seifertm
Copy link
Contributor

@chaokunyang pytest-asyncio uses --asyncio-mode=strict by default since v0.19. Strict mode ignores fixtures decorated with @pytest.fixture. You should use @pytest_asyncio.fixture instead (see Async Fixtures).

Can you try this and report back, please?

@chaokunyang
Copy link
Author

Fixed issue with strict pytest-asyncio breaking OpenMined/PySyft#6643

thanks, @pytest_asyncio.fixture works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants