Skip to content

Commit 2c73ce7

Browse files
committed
prune_pytest_as_errors
1 parent b2ad93a commit 2c73ce7

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

.actions/assistant.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,25 @@ def generate_docker_tags(
459459
tags = [f"{docker_project}:{tag}" for tag in tags]
460460
print(",".join(tags))
461461

462+
@staticmethod
463+
def prune_pytest_as_errors(
464+
pyproject_toml: str = "pyproject.toml", errors: tuple = ("FutureWarning", "DeprecationWarning")
465+
) -> None:
466+
"""Prune pytest warnings as errors from the pyproject.toml file."""
467+
import toml
468+
469+
with open(pyproject_toml, encoding="utf-8") as fopen:
470+
pyproject = toml.load(fopen)
471+
filterwarnings = pyproject.get("tool", {}).get("pytest", {}).get("ini_options", {}).get("filterwarnings", [])
472+
if not filterwarnings:
473+
return
474+
print(filterwarnings)
475+
print([f"error::{err}" for err in errors])
476+
filterwarnings = [wrn for wrn in filterwarnings if not any(f"error::{err}" in wrn for err in errors)]
477+
pyproject["tool"]["pytest"]["ini_options"]["filterwarnings"] = filterwarnings
478+
with open(pyproject_toml, "w", encoding="utf-8") as fopen:
479+
toml.dump(pyproject, fopen)
480+
462481

463482
if __name__ == "__main__":
464483
import jsonargparse

.github/workflows/ci-tests-fabric.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
uv pip install "cython<3.0" wheel
106106
uv pip install "pyyaml==5.4" --no-build-isolation
107107
# This script removes any line containing "error::FutureWarning" from pyproject.toml
108-
sed -i '/error::FutureWarning/d' pyproject.toml
108+
python .actions/assistant.py prune_pytest_as_errors
109109
110110
- name: Adjust PyTorch versions in requirements files
111111
if: ${{ matrix.config.requires != 'oldest' }}

.github/workflows/ci-tests-pytorch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
uv pip install "cython<3.0" wheel
105105
uv pip install "pyyaml==5.4" --no-build-isolation
106106
# This script removes any line containing "error::FutureWarning" from pyproject.toml
107-
sed -i '/error::FutureWarning/d' pyproject.toml
107+
python .actions/assistant.py prune_pytest_as_errors
108108
109109
- name: Adjust PyTorch versions in requirements files
110110
if: ${{ matrix.config.requires != 'oldest' }}

0 commit comments

Comments
 (0)