@@ -315,24 +315,106 @@ class MyReporter(TerminalReporter):
315315 def short_test_summary (self ):
316316 # your own impl goes here, for example:
317317 self .write_sep ("=" , "PyMAPDL Pytest short summary" )
318+ markup = self ._tw .markup
319+
320+ if self .hasmarkup :
321+ color = True
322+ else :
323+ color = False
324+
325+ ERROR_COLOR = {"Red" : color , "bold" : True }
326+ FAILED_COLOR = {"red" : color , "bold" : True }
327+ PASSED_COLOR = {"green" : color }
328+ SKIPPED_COLOR = {"green" : color , "bold" : True }
329+ XPASSED_COLOR = {"Yellow" : color , "bold" : True }
330+ XFAILED_COLOR = {"yellow" : color }
331+
332+ # self._tw.markup("asdf", Red=True)
333+
334+ def get_normal_message (rep , header , message ):
335+ location = rep .location
336+ if message :
337+ message = f" - { message } "
338+
339+ if location [0 ] == location [2 ]:
340+ return f"{ header } { rep .head_line } { message } "
341+ else :
342+ path = f"{ location [0 ]} :{ location [1 ]} "
343+ return f"{ header } { rep .head_line } - { path } { message } "
344+
345+ def get_failure_message (rep , header , message ):
346+ location = rep .location
347+ path = f"{ location [0 ]} :{ location [1 ]} "
348+ cause = message .splitlines ()
349+ cause = " " .join (
350+ [
351+ each [2 :].strip () if each .startswith ("E " ) else each .strip ()
352+ for each in cause
353+ ]
354+ )
355+
356+ return f"{ header } { rep .head_line } - { path } : { cause } "
357+
358+ def get_skip_message (rep ):
359+ message = rep .longrepr [2 ]
360+ header = markup ("[SKIPPED]" , ** SKIPPED_COLOR )
361+ return get_normal_message (rep , header , message )
362+
363+ def get_passed_message (rep ):
364+ message = rep .longreprtext
365+ header = markup ("[PASSED]" , ** PASSED_COLOR )
366+ return get_normal_message (rep , header , message )
367+
368+ def get_xfailed_message (rep ):
369+ message = " " .join (rep .longrepr .reprcrash .message .split (":" )[1 :]).strip ()
370+ header = markup ("[XFAILED]" , ** XFAILED_COLOR )
371+ return get_normal_message (rep , header , message )
372+
373+ def get_xpassed_message (rep ):
374+ message = rep .longreprtext
375+ header = markup ("[XPASSED]" , ** XPASSED_COLOR )
376+ return get_normal_message (rep , header , message )
377+
378+ def get_error_message (rep ):
379+ message = rep .longrepr .reprcrash .message
380+ header = markup ("[ERROR]" , ** ERROR_COLOR )
381+ return get_failure_message (rep , header , message )
382+
383+ def get_failed_message (rep ):
384+ message = rep .longrepr .reprcrash .message
385+ header = markup ("[FAILED]" , ** FAILED_COLOR )
386+ return get_failure_message (rep , header , message )
318387
319388 failed = self .stats .get ("failed" , [])
320389 for rep in failed :
321- self .write_line (
322- f"[FAILED] { rep .head_line } - { rep .longreprtext .splitlines ()[- 3 ]} "
323- )
390+ self .write_line (get_failed_message (rep ))
391+
392+ skipped = self .stats .get ("skipped" , [])
393+ for rep in skipped :
394+ self .write_line (get_skip_message (rep ))
324395
325396 errored = self .stats .get ("error" , [])
326397 for rep in errored :
327- self .write_line (
328- f"[ERROR] { rep .head_line } - { rep .longreprtext .splitlines ()[- 3 ]} "
329- )
398+ self .write_line (get_error_message (rep ))
399+
400+ passed = self .stats .get ("passed" , [])
401+ for rep in passed :
402+ self .write_line (get_passed_message (rep ))
403+
404+ xpassed = self .stats .get ("xpassed" , [])
405+ for rep in xpassed :
406+ self .write_line (get_xpassed_message (rep ))
407+
408+ xfailed = self .stats .get ("xfailed" , [])
409+ for rep in xfailed :
410+ self .write_line (get_xfailed_message (rep ))
330411
331412
332413@pytest .hookimpl (trylast = True )
333414def pytest_configure (config ):
334415 vanilla_reporter = config .pluginmanager .getplugin ("terminalreporter" )
335416 my_reporter = MyReporter (config )
417+ my_reporter ._tw .fullwidth = 160
336418 config .pluginmanager .unregister (vanilla_reporter )
337419 config .pluginmanager .register (my_reporter , "terminalreporter" )
338420
0 commit comments