|
| 1 | +[tox] |
| 2 | +isolated_build = true |
| 3 | +# Version 4.22 is the first one to implement support for dependency groups: |
| 4 | +minversion = 4.22 |
| 5 | + |
| 6 | + |
| 7 | +[python-cli-options] |
| 8 | +byte-warnings = -b |
| 9 | +byte-errors = -bb |
| 10 | +max-isolation = -E -s -I |
| 11 | +some-isolation = -E -s |
| 12 | +warnings-to-errors = -Werror |
| 13 | + |
| 14 | + |
| 15 | +[testenv] |
| 16 | +description = Run pytest under {envpython} |
| 17 | +dependency_groups = |
| 18 | + testing |
| 19 | +commands = |
| 20 | + {envpython} \ |
| 21 | + {[python-cli-options]byte-errors} \ |
| 22 | + {[python-cli-options]max-isolation} \ |
| 23 | + {[python-cli-options]warnings-to-errors} \ |
| 24 | + -W 'ignore:Coverage failure::pytest_cov.plugin' \ |
| 25 | + -m pytest \ |
| 26 | + {tty:--color=yes} \ |
| 27 | + {posargs:--cov-report=html:{envtmpdir}{/}htmlcov{/}} |
| 28 | +commands_post = |
| 29 | + -{envpython} \ |
| 30 | + {[python-cli-options]byte-errors} \ |
| 31 | + {[python-cli-options]max-isolation} \ |
| 32 | + {[python-cli-options]warnings-to-errors} \ |
| 33 | + -c \ |
| 34 | + 'import atexit, os, sys; \ |
| 35 | + os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \ |
| 36 | + import coverage; \ |
| 37 | + gh_summary_fd = open(\ |
| 38 | + os.environ["GITHUB_STEP_SUMMARY"], encoding="utf-8", mode="a",\ |
| 39 | + ); \ |
| 40 | + atexit.register(gh_summary_fd.close); \ |
| 41 | + cov = coverage.Coverage(); \ |
| 42 | + cov.load(); \ |
| 43 | + cov.report(file=gh_summary_fd, output_format="markdown")' |
| 44 | + {envpython} \ |
| 45 | + {[python-cli-options]byte-errors} \ |
| 46 | + {[python-cli-options]max-isolation} \ |
| 47 | + {[python-cli-options]warnings-to-errors} \ |
| 48 | + -c \ |
| 49 | + 'import os, pathlib, sys; \ |
| 50 | + os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \ |
| 51 | + cov_report_arg_prefix = "--cov-report=xml:"; \ |
| 52 | + test_report_arg_prefix = "--junitxml="; \ |
| 53 | + cov_reports = [\ |
| 54 | + arg[len(cov_report_arg_prefix):] for arg in sys.argv \ |
| 55 | + if arg.startswith(cov_report_arg_prefix)\ |
| 56 | + ]; \ |
| 57 | + test_reports = [\ |
| 58 | + arg[len(test_report_arg_prefix):] for arg in sys.argv \ |
| 59 | + if arg.startswith(test_report_arg_prefix)\ |
| 60 | + ]; \ |
| 61 | + cov_report_file = cov_reports[-1] if cov_reports else None; \ |
| 62 | + test_report_file = test_reports[-1] if test_reports else None; \ |
| 63 | + gh_output_fd = open(\ |
| 64 | + os.environ["GITHUB_OUTPUT"], encoding="utf-8", mode="a",\ |
| 65 | + ); \ |
| 66 | + cov_report_file and \ |
| 67 | + print(f"cov-report-files={cov_report_file !s}", file=gh_output_fd); \ |
| 68 | + test_report_file and \ |
| 69 | + print(f"test-result-files={test_report_file !s}", file=gh_output_fd); \ |
| 70 | + print("codecov-flags=pytest", file=gh_output_fd); \ |
| 71 | + gh_output_fd.close()' \ |
| 72 | + {posargs} |
| 73 | + # Print out the output coverage dir and a way to serve html: |
| 74 | + {envpython} \ |
| 75 | + {[python-cli-options]byte-errors} \ |
| 76 | + {[python-cli-options]max-isolation} \ |
| 77 | + {[python-cli-options]warnings-to-errors} \ |
| 78 | + -c\ |
| 79 | + 'import pathlib, shlex, sys; \ |
| 80 | + cov_html_report_arg_prefix = "--cov-report=html:"; \ |
| 81 | + cov_html_reports = [\ |
| 82 | + arg[len(cov_html_report_arg_prefix):] for arg in sys.argv \ |
| 83 | + if arg.startswith(cov_html_report_arg_prefix)\ |
| 84 | + ]; \ |
| 85 | + cov_html_reports or sys.exit(); \ |
| 86 | + cov_html_report_dir = pathlib.Path(cov_html_reports[-1]); \ |
| 87 | + index_file = cov_html_report_dir / "index.html";\ |
| 88 | + index_file.exists() or sys.exit(); \ |
| 89 | + html_url = f"file://\{index_file\}";\ |
| 90 | + browse_cmd = shlex.join(("python3", "-Im", "webbrowser", html_url)); \ |
| 91 | + serve_cmd = shlex.join((\ |
| 92 | + "python3", "-Im", "http.server", \ |
| 93 | + "--directory", str(cov_html_report_dir), "0", \ |
| 94 | + )); \ |
| 95 | + print(f"\nTo open the HTML coverage report, run\n\n\ |
| 96 | + \t\{browse_cmd !s\}\n");\ |
| 97 | + print(f"To serve \ |
| 98 | + the HTML coverage report with a local web server, use\n\n\ |
| 99 | + \t\{serve_cmd !s\}\n")' \ |
| 100 | + {posargs:--cov-report=html:{envtmpdir}{/}htmlcov{/}} |
| 101 | +package = editable |
| 102 | +pass_env = |
| 103 | + CI |
| 104 | + GITHUB_* |
| 105 | + SSH_AUTH_SOCK |
| 106 | + TERM |
| 107 | +set_env = |
| 108 | + COVERAGE_PROCESS_START = {toxinidir}{/}.coveragerc |
| 109 | +wheel_build_env = .pkg |
0 commit comments