-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_annotated.py
75 lines (54 loc) · 1.78 KB
/
test_annotated.py
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
from typing import Annotated
from pytest import ExitCode, Pytester
from pytest_annotated import Fixture
from tests.conftest import ConftestFixtureResult
from tests.random_module import RandomFixtureResult, random_fixture2
def test_annotated(
c: Annotated[ConftestFixtureResult, Fixture()],
):
assert isinstance(c, ConftestFixtureResult)
def test_annotated_without_explicit_fixture(
c: Annotated[ConftestFixtureResult, ""],
):
assert isinstance(c, ConftestFixtureResult)
def test_annotated_only_type(
c: ConftestFixtureResult,
):
assert isinstance(c, ConftestFixtureResult)
def test_use_annotated_as_regular(conftest_fixture):
assert isinstance(conftest_fixture, ConftestFixtureResult)
def test_use_regular_that_uses_annotated(regular_fixture):
assert isinstance(regular_fixture, int)
def test_use_from_random_module(
r: Annotated[RandomFixtureResult, Fixture()],
):
assert isinstance(r, RandomFixtureResult)
assert r.value == 1
def test_use_from_random_module_with_explicit_func(
r: Annotated[RandomFixtureResult, Fixture(random_fixture2)],
):
assert isinstance(r, RandomFixtureResult)
assert r.value == 2
def test_fixture_with_missing_annotation(pytester: Pytester):
pytester.makeconftest(
"""
import pytest
import pytest_annotated
@pytest_annotated.fixture
def name(request):
return request.param
"""
)
pytester.makepyfile(
"""
def test_thing(name):
assert name is not None
"""
)
result = pytester.runpytest()
assert result.ret is ExitCode.USAGE_ERROR
assert any(
"Cannot use pytest_annotated.fixture without specifying the return type in the signature"
in line
for line in result.stderr.lines
)