Skip to content

Commit

Permalink
benchmark: force mypy to measure line coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jun 23, 2024
1 parent f572e3a commit b8739dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ class ToxProject(ProjectToTest):
env_vars: Env_VarsType = {
**(ProjectToTest.env_vars or {}),
# Allow some environment variables into the tox execution.
"TOX_OVERRIDE": "testenv.pass_env+=COVERAGE_DEBUG,COVERAGE_CORE",
"TOX_OVERRIDE": "testenv.pass_env+=COVERAGE_DEBUG,COVERAGE_CORE,COVERAGE_FORCE_CONFIG",
"COVERAGE_DEBUG": "config,sys",
}

def prep_environment(self, env: Env) -> None:
Expand Down Expand Up @@ -579,9 +580,12 @@ def run_no_coverage(self, env: Env) -> float:

def run_with_coverage(self, env: Env, cov_ver: Coverage) -> float:
env.shell.run_command(f"{env.python} -m pip install {cov_ver.pip_args}")
env.shell.run_command(f"{env.python} -m pytest {self.FAST} --cov")
duration = env.shell.last_duration
report = env.shell.run_command(f"{env.python} -m coverage report --precision=6")
pforce = Path("force.ini")
pforce.write_text("[run]\nbranch=false\n")
with env.shell.set_env({"COVERAGE_FORCE_CONFIG": str(pforce.resolve())}):
env.shell.run_command(f"{env.python} -m pytest {self.FAST} --cov")
duration = env.shell.last_duration
report = env.shell.run_command(f"{env.python} -m coverage report --precision=6")
print("Results:", report.splitlines()[-1])
return duration

Expand Down
8 changes: 4 additions & 4 deletions benchmark/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
],
cov_versions=[
NoCoverage("nocov"),
Coverage("753", "coverage==7.5.3"),
Coverage("sysmon", "coverage==7.5.3", env_vars={"COVERAGE_CORE": "sysmon"}),
CoverageSource(slug="ctrace", env_vars={"COVERAGE_CORE": "ctrace"}),
CoverageSource(slug="sysmon", env_vars={"COVERAGE_CORE": "sysmon"}),
],
projects=[
# ProjectSphinx(), # Works, slow
Expand All @@ -115,14 +115,14 @@
# ProjectDulwich(), # Works
# ProjectBlack(), # Works, slow
# ProjectMpmath(), # Works, slow
# ProjectMypy(), # Works, slow
ProjectMypy(), # Works, slow
# ProjectHtml5lib(), # Works
# ProjectUrllib3(), # Works
],
rows=["pyver", "proj"],
column="cov",
ratios=[
(f"753%", "753", "nocov"),
(f"ctrace%", "ctrace", "nocov"),
(f"sysmon%", "sysmon", "nocov"),
],
load=True,
Expand Down

0 comments on commit b8739dd

Please sign in to comment.