|
19 | 19 |
|
20 | 20 | import trio
|
21 | 21 | import trio.testing
|
22 |
| -from trio._tests.pytest_plugin import skip_if_optional_else_raise |
| 22 | +from trio._tests.pytest_plugin import RUN_SLOW, skip_if_optional_else_raise |
23 | 23 |
|
24 | 24 | from .. import _core, _util
|
25 | 25 | from .._core._tests.tutil import slow
|
26 |
| -from .pytest_plugin import RUN_SLOW |
27 | 26 |
|
28 | 27 | if TYPE_CHECKING:
|
29 | 28 | from collections.abc import Iterable, Iterator
|
@@ -574,3 +573,37 @@ def test_classes_are_final() -> None:
|
574 | 573 | continue
|
575 | 574 |
|
576 | 575 | assert class_is_final(class_)
|
| 576 | + |
| 577 | + |
| 578 | +# Plugin might not be running, especially if running from an installed version. |
| 579 | +@pytest.mark.skipif( |
| 580 | + not hasattr(attrs.field, "trio_modded"), |
| 581 | + reason="Pytest plugin not installed.", |
| 582 | +) |
| 583 | +def test_pyright_recognizes_init_attributes() -> None: |
| 584 | + """Check whether we provide `alias` for all underscore prefixed attributes. |
| 585 | +
|
| 586 | + Attrs always sets the `alias` attribute on fields, so a pytest plugin is used |
| 587 | + to monkeypatch `field()` to record whether an alias was defined in the metadata. |
| 588 | + See `_trio_check_attrs_aliases`. |
| 589 | + """ |
| 590 | + for module in PUBLIC_MODULES: |
| 591 | + for class_ in module.__dict__.values(): |
| 592 | + if not attrs.has(class_): |
| 593 | + continue |
| 594 | + if isinstance(class_, _util.NoPublicConstructor): |
| 595 | + continue |
| 596 | + |
| 597 | + attributes = [ |
| 598 | + attr |
| 599 | + for attr in attrs.fields(class_) |
| 600 | + if attr.init |
| 601 | + if attr.alias |
| 602 | + not in ( |
| 603 | + attr.name, |
| 604 | + # trio_original_args may not be present in autoattribs |
| 605 | + attr.metadata.get("trio_original_args", {}).get("alias"), |
| 606 | + ) |
| 607 | + ] |
| 608 | + |
| 609 | + assert attributes == [], class_ |
0 commit comments