Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix coverage combine for different OS's #778

Merged
merged 16 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading