88from contextlib import contextmanager
99from contextlib import ExitStack
1010from contextlib import nullcontext
11+ import dataclasses
1112import sys
1213import time
1314from typing import Any
1415from typing import TYPE_CHECKING
1516from unittest import TestCase
1617
17- import attr
1818import pluggy
1919
2020from _pytest ._code import ExceptionInfo
@@ -58,15 +58,15 @@ def pytest_addoption(parser: Parser) -> None:
5858 )
5959
6060
61- @attr . s
61+ @dataclasses . dataclass
6262class SubTestContext :
63- msg : str | None = attr . ib ()
64- kwargs : dict [str , Any ] = attr . ib ()
63+ msg : str | None
64+ kwargs : dict [str , Any ]
6565
6666
67- @attr . s (init = False )
67+ @dataclasses . dataclass (init = False )
6868class SubTestReport (TestReport ): # type: ignore[misc]
69- context : SubTestContext = attr . ib ()
69+ context : SubTestContext
7070
7171 @property
7272 def head_line (self ) -> str :
@@ -88,7 +88,7 @@ def _to_json(self) -> dict[str, Any]:
8888 data = super ()._to_json ()
8989 del data ["context" ]
9090 data ["_report_type" ] = "SubTestReport"
91- data ["_subtest.context" ] = attr .asdict (self .context )
91+ data ["_subtest.context" ] = dataclasses .asdict (self .context )
9292 return data
9393
9494 @classmethod
@@ -232,11 +232,11 @@ def subtests(request: SubRequest) -> Generator[SubTests, None, None]:
232232 yield SubTests (request .node .ihook , suspend_capture_ctx , request )
233233
234234
235- @attr . s
235+ @dataclasses . dataclass
236236class SubTests :
237- ihook : pluggy .HookRelay = attr . ib ()
238- suspend_capture_ctx : Callable [[], AbstractContextManager [None ]] = attr . ib ()
239- request : SubRequest = attr . ib ()
237+ ihook : pluggy .HookRelay
238+ suspend_capture_ctx : Callable [[], AbstractContextManager [None ]]
239+ request : SubRequest
240240
241241 @property
242242 def item (self ) -> Any :
@@ -267,7 +267,7 @@ def test(
267267 )
268268
269269
270- @attr . s ( auto_attribs = True )
270+ @dataclasses . dataclass
271271class _SubTestContextManager :
272272 """
273273 Context manager for subtests, capturing exceptions raised inside the subtest scope and handling
@@ -423,10 +423,10 @@ def ignore_pytest_private_warning() -> Generator[None, None, None]:
423423 yield
424424
425425
426- @attr . s
426+ @dataclasses . dataclass ()
427427class Captured :
428- out = attr . ib ( default = "" , type = str )
429- err = attr . ib ( default = "" , type = str )
428+ out : str = ""
429+ err : str = ""
430430
431431 def update_report (self , report : TestReport ) -> None :
432432 if self .out :
0 commit comments