File tree Expand file tree Collapse file tree 3 files changed +28
-14
lines changed
Expand file tree Collapse file tree 3 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -70,9 +70,10 @@ those who use PyTest, when using PyScript.
7070 ` setup ` and ` teardown ` functions can be overridden in the individual test
7171 modules.
72727 . The ` result ` of awaiting ` upytest.run ` is a Python dictionary containing
73- lists of tests bucketed under the keys: ` "passes" ` , ` "fails" ` and
74- ` "skipped" ` . These results can be used for further processing and analysis
75- (again, see ` main.py ` for an example of this in action.)
73+ lists of tests bucketed under the keys: ` "passes" ` , ` "fails" ` and
74+ ` "skipped" ` . These results are JSON serializable and can be used for further
75+ processing and analysis (again, see ` main.py ` for an example of this in
76+ action.)
76778 . In your ` index.html ` make sure you use the ` terminal ` attribute
7778 when referencing your Python script (as in the ` index.html ` file in
7879 this repository):
Original file line number Diff line number Diff line change 7979 actual == value
8080 ), f"Expected { value } { key } in { name } , got { actual } "
8181
82- # Ensure the tests that pass have a name ending in "passed ", tests that fail
83- # have a name ending in "failed ", and tests that are skipped have a name ending
82+ # Ensure the tests that pass have a name ending in "passes ", tests that fail
83+ # have a name ending in "fails ", and tests that are skipped have a name ending
8484# in "skipped".
85- for name , result in actual_results .items ():
86- for key , value in result .items ():
87- for test in value :
88- assert test . test_name .endswith (
89- key
90- ), f"Test { test . test_name } does not end with { key } "
85+ for test_run , result in actual_results .items (): # result_all, result_module, etc.
86+ for test_status , matching_tests in result .items (): # passes, fails, skipped
87+ for test in matching_tests :
88+ assert test [ " test_name" ] .endswith (
89+ test_status
90+ ), f"Test { test [ " test_name" ] } does not end with { test_status } "
9191
9292# Create a div to display the results in the page.
9393page .append (
Original file line number Diff line number Diff line change @@ -158,6 +158,19 @@ async def run(self):
158158 self .status = FAIL
159159 self .traceback = parse_traceback_from_exception (ex )
160160
161+ @property
162+ def as_dict (self ):
163+ """
164+ Return a dictionary representation of the test case.
165+ """
166+ return {
167+ "module_name" : self .module_name ,
168+ "test_name" : self .test_name ,
169+ "status" : self .status ,
170+ "traceback" : self .traceback ,
171+ "reason" : self .reason ,
172+ }
173+
161174
162175class TestModule :
163176 """
@@ -508,7 +521,7 @@ async def run(*args, **kwargs):
508521 f"\033 [1m{ error_count } \033 [0m \033 [31;1mfailed\033 [0m, \033 [1m{ skip_count } \033 [0m \033 [33;1mskipped\033 [0m, \033 [1m{ pass_count } \033 [0m \033 [32;1mpassed\033 [0m in \033 [1m{ dur :.2f} seconds\033 [0m"
509522 )
510523 return {
511- "passes" : passed_tests ,
512- "fails" : failed_tests ,
513- "skipped" : skipped_tests ,
524+ "passes" : [ test . as_dict for test in passed_tests ] ,
525+ "fails" : [ test . as_dict for test in failed_tests ] ,
526+ "skipped" : [ test . as_dict for test in skipped_tests ] ,
514527 }
You can’t perform that action at this time.
0 commit comments