@@ -21,27 +21,30 @@ def __init__(self, extension=None):
21
21
"""An approval tests Namer for naming approved and received text files.
22
22
23
23
These files will get stored under:
24
- `tests/approval/{module}/test_file.py:: TestClass:: test_func[a]`
24
+ `tests/approval/{module}/test_file.py-- TestClass-- test_func[a]`
25
25
26
26
This class utilizes the `PYTEST_CURRENT_TEST` environment variable, which
27
27
consist of the nodeid and the current stage:
28
28
`relative/path/to/test_file.py::TestClass::test_func[a] (call)`
29
+
30
+ During a pytest test session stages can be setup, teardown or call.
31
+ Approval tests should only be used during the call stage and therefore
32
+ the ` (call)` postfix is removed.
33
+
34
+ To avoid forbidden characters in system paths `::` is replaced by `-`.
29
35
"""
30
- self .nodeid = os .environ ["PYTEST_CURRENT_TEST" ]
36
+ self .nodeid : Path = Path ( os .environ ["PYTEST_CURRENT_TEST" ])
31
37
NamerBase .__init__ (self , extension )
32
38
33
- def get_file_name (self ) -> str :
39
+ def get_file_name (self ) -> Path :
34
40
"""File name is pytest nodeid w/out directory name and pytest stage."""
35
- # During a pytest test session stages can be setup, teardown or call.
36
- # Approval tests should only be used during the call stage and therefore
37
- # we replace the ` (call)` postfix.
38
- return self .nodeid .split ("/" )[- 1 ].replace (" (call)" , "" )
41
+ return Path (str (self .nodeid .name ).replace (" (call)" , "" ).replace ("::" , "-" ))
39
42
40
43
def get_directory (self ) -> Path :
41
44
"""Directory is `tests/approval/{module}`."""
42
- parts = self .nodeid .split ( "/" )[: - 1 ]
43
- directory = "/" . join ( parts )
44
- return Path (APPROVED_DIR ) / directory . replace ( "tests/integrationtests/" , "" )
45
+ parts = self .nodeid .parent . parts
46
+ raw = Path ( * [ p for p in parts if p not in [ "tests" , "integrationtests" ]] )
47
+ return Path (APPROVED_DIR ) / raw
45
48
46
49
def get_config (self ) -> dict :
47
50
return {}
0 commit comments