|
1 | 1 | from mypy.nodes import Decorator |
2 | 2 | from mypy.subtypes import is_same_type |
| 3 | +from mypy.types import CallableType |
3 | 4 | import pytest |
4 | 5 |
|
5 | | -from .fixture import Fixture, FixtureParser |
| 6 | +from .fixture import Fixture, FixtureParser, FixtureScope |
6 | 7 | from .test_utils import check_error_messages, get_error_messages, parse |
7 | 8 |
|
8 | 9 |
|
@@ -247,6 +248,55 @@ def fixture(x, y): |
247 | 248 | ) |
248 | 249 |
|
249 | 250 |
|
| 251 | +def _fixture_from_type_test_body(defs: str) -> None: |
| 252 | + parse_result = parse(defs) |
| 253 | + fixture_node = parse_result.defs["fixture"] |
| 254 | + assert isinstance(fixture_node, Decorator) |
| 255 | + |
| 256 | + checker = parse_result.checker |
| 257 | + parse_result.accept_all() |
| 258 | + |
| 259 | + fixture_type = fixture_node.func.type |
| 260 | + assert isinstance(fixture_type, CallableType) |
| 261 | + fixture_type.definition = None |
| 262 | + |
| 263 | + fixture = Fixture.from_type( |
| 264 | + fixture_type, |
| 265 | + scope=FixtureScope.module, |
| 266 | + file="", |
| 267 | + is_generator=False, |
| 268 | + fullname="test_module.fullname", |
| 269 | + ) |
| 270 | + assert fixture is not None |
| 271 | + |
| 272 | + messages = get_error_messages(checker) |
| 273 | + assert not checker.errors.is_errors(), messages |
| 274 | + |
| 275 | + |
| 276 | +def test_fixture_from_types_no_args() -> None: |
| 277 | + _fixture_from_type_test_body( |
| 278 | + """ |
| 279 | + import pytest |
| 280 | +
|
| 281 | + @pytest.fixture |
| 282 | + def fixture() -> None: |
| 283 | + ... |
| 284 | + """ |
| 285 | + ) |
| 286 | + |
| 287 | + |
| 288 | +def test_fixture_from_type_some_args() -> None: |
| 289 | + _fixture_from_type_test_body( |
| 290 | + """ |
| 291 | + import pytest |
| 292 | +
|
| 293 | + @pytest.fixture |
| 294 | + def fixture(x: int, y: bool) -> None: |
| 295 | + ... |
| 296 | + """ |
| 297 | + ) |
| 298 | + |
| 299 | + |
250 | 300 | def fixture_return_type_test_body(defs: str, is_generator: bool) -> None: |
251 | 301 | parse_result = parse(defs) |
252 | 302 | original_type = parse_result.types["original"] |
|
0 commit comments