3131import inspect
3232import time
3333from pathlib import Path
34+ import asyncio
3435from pyscript import RUNNING_IN_WORKER
3536
3637try :
@@ -260,14 +261,17 @@ def limit_tests_to(self, test_names):
260261 or (t .test_name .split ("." )[0 ] in test_names )
261262 ]
262263
263- def print (self , text ):
264+ async def print (self , text ):
264265 """
265266 Print the provided text to the console.
266267 """
267268 if is_micropython :
268269 # MicroPython doesn't flush.
269270 print (text , end = "" )
270271 else :
272+ if not RUNNING_IN_WORKER :
273+ # Ensure print is non-blocking in Pyodide on main thread.
274+ await asyncio .sleep (0 )
271275 print (text , end = "" , flush = True )
272276
273277 async def run (self ):
@@ -279,6 +283,7 @@ async def run(self):
279283 Print a dot for each passing test, an F for each failing test, and an S
280284 for each skipped test.
281285 """
286+ print (f"\n { self .path } : " , end = "" )
282287 for test_case in self .tests :
283288 if self .setup :
284289 if is_awaitable (self .setup ):
@@ -292,11 +297,11 @@ async def run(self):
292297 else :
293298 self .teardown ()
294299 if test_case .status == SKIPPED :
295- self .print ("\033 [33;1mS\033 [0m" )
300+ await self .print ("\033 [33;1mS\033 [0m" )
296301 elif test_case .status == PASS :
297- self .print ("\033 [32;1m.\033 [0m" )
302+ await self .print ("\033 [32;1m.\033 [0m" )
298303 else :
299- self .print ("\033 [31;1mF\033 [0m" )
304+ await self .print ("\033 [31;1mF\033 [0m" )
300305
301306
302307def gather_conftest_functions (conftest_path , target ):
@@ -470,7 +475,7 @@ async def run(*args, **kwargs):
470475 module_count = len (test_modules )
471476 test_count = sum ([len (module .tests ) for module in test_modules ])
472477 print (
473- f"Found { module_count } test module[s]. Running { test_count } test[s].\n "
478+ f"Found { module_count } test module[s]. Running { test_count } test[s]."
474479 )
475480
476481 failed_tests = []
@@ -487,7 +492,7 @@ async def run(*args, **kwargs):
487492 elif test .status == PASS :
488493 passed_tests .append (test )
489494 end = time .time ()
490- print ("" )
495+ print ("\n " )
491496 if failed_tests :
492497 print (
493498 "================================= \033 [31;1mFAILURES\033 [0m ================================="
@@ -502,7 +507,7 @@ async def run(*args, **kwargs):
502507 "\033 [0m" ,
503508 sep = "" ,
504509 )
505- print (failed .traceback )
510+ print (failed .traceback . strip () )
506511 if failed != failed_tests [- 1 ]:
507512 print ("" )
508513 if skipped_tests :
0 commit comments