Skip to content

Commit

Permalink
ci: fix coverage combine for different OS's (#778)
Browse files Browse the repository at this point in the history
* ci: fix coverage combine for different OS's

Signed-off-by: Henry Schreiner <[email protected]>

* tests: remove some coverage ignore pragmas

Signed-off-by: Henry Schreiner <[email protected]>

* ci: manually ignore broken path on Windows

Signed-off-by: Henry Schreiner <[email protected]>

* ci: try to fix paths again

Signed-off-by: Henry Schreiner <[email protected]>

* WIP: add some debugging info

Signed-off-by: Henry Schreiner <[email protected]>

* WIP: fixup

Signed-off-by: Henry Schreiner <[email protected]>

* WIP: try non-editable install

Signed-off-by: Henry Schreiner <[email protected]>

* ci: use module vs. path

Signed-off-by: Henry Schreiner <[email protected]>

* ci: require proper version of coverage

Signed-off-by: Henry Schreiner <[email protected]>

* ci: drop relative paths

Signed-off-by: Henry Schreiner <[email protected]>

* ci: editable install with non-rel paths

Signed-off-by: Henry Schreiner <[email protected]>

* ci: clean up changes

Signed-off-by: Henry Schreiner <[email protected]>

* ci: try adding sources for coverage

Signed-off-by: Henry Schreiner <[email protected]>

* ci: try manually fixing the coverage files on Windows

Signed-off-by: Henry Schreiner <[email protected]>

* ci: try omit instead of changing the sqlite file

Signed-off-by: Henry Schreiner <[email protected]>

* revert: previous commit

---------

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Feb 23, 2024
1 parent 3b8e026 commit 911b800
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions nox/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from packaging.specifiers import InvalidSpecifier, SpecifierSet
from packaging.version import InvalidVersion, Version

if sys.version_info >= (3, 8): # pragma: no cover
if sys.version_info >= (3, 8):
import importlib.metadata as metadata
else: # pragma: no cover
else:
import importlib_metadata as metadata


Expand Down
6 changes: 3 additions & 3 deletions nox/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from nox.logger import logger
from nox.popen import popen

if sys.version_info < (3, 8): # pragma: no cover
if sys.version_info < (3, 8):
from typing_extensions import Literal
else: # pragma: no cover
else:
from typing import Literal

ExternalType = Literal["error", True, False]
Expand Down Expand Up @@ -62,7 +62,7 @@ def _clean_env(env: Mapping[str, str] | None = None) -> dict[str, str] | None:
clean_env: dict[str, str] = {}

# Ensure systemroot is passed down, otherwise Windows will explode.
if sys.platform == "win32": # pragma: no cover
if sys.platform == "win32":
clean_env["SYSTEMROOT"] = os.environ.get("SYSTEMROOT", "")

clean_env.update(env)
Expand Down
8 changes: 2 additions & 6 deletions nox/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,12 @@ def __init__(self, name: str, level: int = logging.NOTSET):
logging.addLevelName(OUTPUT, "OUTPUT")

def success(self, msg: str, *args: Any, **kwargs: Any) -> None:
if self.isEnabledFor(SUCCESS):
if self.isEnabledFor(SUCCESS): # pragma: no cover
self._log(SUCCESS, msg, args, **kwargs)
else: # pragma: no cover
pass

def output(self, msg: str, *args: Any, **kwargs: Any) -> None:
if self.isEnabledFor(OUTPUT):
if self.isEnabledFor(OUTPUT): # pragma: no cover
self._log(OUTPUT, msg, args, **kwargs)
else: # pragma: no cover
pass


logging.setLoggerClass(LoggerWithSuccessAndOutput)
Expand Down
19 changes: 15 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

from __future__ import annotations

import contextlib
import functools
import os
import platform
import shutil
import sqlite3
import sys

import nox
Expand Down Expand Up @@ -49,23 +51,32 @@ def tests(session: nox.Session, tox_version: str) -> None:
if session.python == "3.7" and tox_version == "latest":
return

coverage_file = (
f".coverage.{sys.platform}.{session.python}.tox{tox_version.lstrip('<')}"
)

session.create_tmp() # Fixes permission errors on Windows
session.install("-r", "requirements-test.txt")
session.install("-e", ".[tox_to_nox]")
session.install("-e.[tox_to_nox]")
if tox_version != "latest":
session.install(f"tox{tox_version}")
session.run(
"pytest",
"--cov=nox",
"--cov",
"--cov-config",
"pyproject.toml",
"--cov-report=",
*session.posargs,
env={
"COVERAGE_FILE": f".coverage.{session.python}.tox.{tox_version.lstrip('<')}"
"COVERAGE_FILE": coverage_file,
},
)

if sys.platform.startswith("win"):
with contextlib.closing(sqlite3.connect(coverage_file)) as con, con:
con.execute("UPDATE file SET path = REPLACE(path, '\\', '/')")
con.execute("DELETE FROM file WHERE SUBSTR(path, 2, 1) == ':'")


@nox.session(python=["3.7", "3.8", "3.9", "3.10"], venv_backend="conda")
def conda_tests(session: nox.Session) -> None:
Expand All @@ -84,7 +95,7 @@ def cover(session: nox.Session) -> None:
if ON_WINDOWS_CI:
return

session.install("coverage[toml]")
session.install("coverage[toml]>=5.3")
session.run("coverage", "combine")
session.run("coverage", "report", "--fail-under=100", "--show-missing")
session.run("coverage", "erase")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ testpaths = [ "tests" ]

[tool.coverage.run]
branch = true
relative_files = true
omit = [ "nox/_typing.py" ]
relative_files = true
source_pkgs = [ "nox" ]

[tool.coverage.report]
exclude_lines = [ "pragma: no cover", "if TYPE_CHECKING:", "@overload" ]
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage[toml]>=5.3
flask
myst-parser
pytest>=6.0
Expand Down

0 comments on commit 911b800

Please sign in to comment.