@@ -473,7 +473,7 @@ def _prepare_coverage(session: nox.Session) -> None:
473473 Args:
474474 session: The nox session
475475 """
476- if "--keep-coverage " not in session .posargs :
476+ if "--cov-append " not in session .posargs :
477477 session .run ("rm" , "-rf" , ".coverage" , external = True )
478478
479479
@@ -530,24 +530,23 @@ def _get_report_type(session: nox.Session, custom_marker: str | None) -> str:
530530 return f"{ python_version } _{ report_type } "
531531
532532
533- def _inject_header ( preamble : str , report_type : str , report_file_name : str ) -> None :
534- """Prepend report file with header indicating the report type .
533+ def _inject_headline ( headline : str , file_name : str ) -> None :
534+ """Inject headline into file .
535535
536536 - Checks if report file actually exists
537- - If so, injects header indicating the report type
537+ - If so, injects headline
538538 - If not, does nothing
539539
540540 Args:
541- preamble: Preamble text to inject
542- report_type: Type of the report
543- report_file_name: Name of the report file
541+ headline: Headline to inject as first line
542+ file_name: Name of the report file
544543 """
545- report_file = Path (report_file_name )
546- if report_file .is_file ():
547- header = f"# { preamble } { report_type } \n \n "
548- content = report_file .read_text (encoding = UTF8 )
544+ file = Path (file_name )
545+ if file .is_file ():
546+ header = f"{ headline } \n "
547+ content = file .read_text (encoding = UTF8 )
549548 content = header + content
550- report_file .write_text (content , encoding = UTF8 )
549+ file .write_text (content , encoding = UTF8 )
551550
552551
553552def _run_pytest (
@@ -565,19 +564,7 @@ def _run_pytest(
565564 is_sequential = test_type == "sequential"
566565
567566 # Build base pytest arguments
568- pytest_args = [
569- "pytest" ,
570- "--disable-warnings" ,
571- JUNIT_XML ,
572- "-n" ,
573- "auto" ,
574- "--dist" ,
575- "loadgroup" ,
576- ]
577-
578- # Add coverage append for sequential tests
579- if is_sequential :
580- pytest_args .extend (["--cov-append" ])
567+ pytest_args = ["pytest" , "--disable-warnings" , JUNIT_XML , "-n" , "auto" , "--dist" , "loadgroup" ]
581568
582569 # Add act environment filter if needed
583570 if _is_act_environment ():
@@ -589,11 +576,8 @@ def _run_pytest(
589576 marker_value += f" and ({ custom_marker } )"
590577 pytest_args .extend (["-m" , marker_value ])
591578
592- # Add additional arguments and report output
593- # Add any additional posargs except for --keep-coverage
594- for arg in posargs :
595- if arg != "--keep-coverage" :
596- pytest_args .extend ([arg ])
579+ # Add additional arguments
580+ pytest_args .extend (posargs )
597581
598582 # Report output as markdown for GitHub step summaries
599583 report_file_name = f"reports/pytest_{ report_type } _{ 'sequential' if is_sequential else 'parallel' } .md"
@@ -608,21 +592,20 @@ def _run_pytest(
608592 # Run pytest with the constructed arguments
609593 session .run (* pytest_args )
610594
611- # Inject header into the report file indicating the report type
612- _inject_header ( " Failing tests with for test execution with " , report_type , report_file_name )
595+ # Inject headline into the report file indicating the report type
596+ _inject_headline ( f"# Failing tests with for test execution with { report_type } \n " , report_file_name )
613597
614598
615- def _generate_coverage_report (session : nox .Session , report_type : str ) -> None :
599+ def _generate_coverage_report (session : nox .Session ) -> None :
616600 """Generate coverage report in markdown format.
617601
618602 Args:
619603 session: The nox session
620- report_type: Report type string for output files
621604 """
622- coverage_report_file_name = f "reports/coverage_ { report_type } .md"
605+ coverage_report_file_name = "reports/coverage .md"
623606 with Path (coverage_report_file_name ).open ("w" , encoding = UTF8 ) as outfile :
624607 session .run ("coverage" , "report" , "--format=markdown" , stdout = outfile )
625- _inject_header ( " Coverage report for " , report_type , coverage_report_file_name )
608+ _inject_headline ( "# Coverage report" , coverage_report_file_name )
626609
627610
628611def _cleanup_test_execution (session : nox .Session ) -> None :
@@ -650,6 +633,7 @@ def test(session: nox.Session) -> None:
650633 _setup_venv (session )
651634
652635 # Conditionally clean coverage data
636+ # Will remove .coverage file if --cov-append is not specified
653637 _prepare_coverage (session )
654638
655639 # Extract custom markers from posargs if present
@@ -662,10 +646,12 @@ def test(session: nox.Session) -> None:
662646 _run_pytest (session , "not sequential" , custom_marker , filtered_posargs , report_type )
663647
664648 # Run sequential tests
649+ if "--cov-append" not in filtered_posargs :
650+ filtered_posargs .extend (["--cov-append" ])
665651 _run_pytest (session , "sequential" , custom_marker , filtered_posargs , report_type )
666652
667653 # Generate coverage report in markdown
668- _generate_coverage_report (session , report_type )
654+ _generate_coverage_report (session )
669655
670656 # Clean up post test execution
671657 _cleanup_test_execution (session )
0 commit comments