2
1

sample_python_pytest_asyncio.py 365 B

12345678910111213141516171819202122232425262728293031
  1. import asyncio
  2. import pytest
  3. x = 1
  4. @pytest.fixture()
  5. def f1():
  6. global x
  7. x = 2
  8. yield 15
  9. x = 3
  10. @pytest.mark.asyncio
  11. async def test_1():
  12. assert x == 1
  13. @pytest.mark.asyncio
  14. async def test_2(f1):
  15. assert x == 2
  16. assert f1 == 15
  17. @pytest.mark.asyncio
  18. async def test_3():
  19. assert x == 3
  20. await asyncio.sleep(0.1)
  21. assert x == 3