1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
import pytest
def test_async_test_is_executed(testdir):
testdir.makepyfile(
"""
import pytest
import trio
async_test_called = False
@pytest.mark.trio
async def test_base():
global async_test_called
await trio.sleep(0)
async_test_called = True
def test_check_async_test_called():
assert async_test_called
"""
)
result = testdir.runpytest("-s")
result.assert_outcomes(passed=2)
def test_async_test_as_class_method(testdir):
testdir.makepyfile(
"""
import pytest
import trio
async_test_called = False
@pytest.fixture
async def fix():
await trio.sleep(0)
return 'fix'
class TestInClass:
@pytest.mark.trio
async def test_base(self, fix):
global async_test_called
assert fix == 'fix'
await trio.sleep(0)
async_test_called = True
def test_check_async_test_called():
assert async_test_called
"""
)
result = testdir.runpytest()
result.assert_outcomes(passed=2)
@pytest.mark.xfail(reason="Raises pytest internal error so far...")
def test_sync_function_with_trio_mark(testdir):
testdir.makepyfile(
"""
import pytest
@pytest.mark.trio
def test_invalid():
pass
"""
)
result = testdir.runpytest()
result.assert_outcomes(errors=1)
def test_skip_and_xfail(testdir):
testdir.makepyfile(
"""
import functools
import pytest
import trio
trio.run = functools.partial(trio.run, strict_exception_groups=True)
@pytest.mark.trio
async def test_xfail():
pytest.xfail()
@pytest.mark.trio
async def test_skip():
pytest.skip()
async def callback(fn):
fn()
async def fail():
raise RuntimeError
@pytest.mark.trio
async def test_xfail_and_fail():
async with trio.open_nursery() as nursery:
nursery.start_soon(callback, pytest.xfail)
nursery.start_soon(fail)
@pytest.mark.trio
async def test_skip_and_fail():
async with trio.open_nursery() as nursery:
nursery.start_soon(callback, pytest.skip)
nursery.start_soon(fail)
@pytest.mark.trio
async def test_xfail_and_skip():
async with trio.open_nursery() as nursery:
nursery.start_soon(callback, pytest.skip)
nursery.start_soon(callback, pytest.xfail)
"""
)
result = testdir.runpytest("-s")
result.assert_outcomes(skipped=1, xfailed=1, failed=3)
|