Skip to content

Commit

Permalink
Minor test improvements (#4234)
Browse files Browse the repository at this point in the history
- disable coloring during testing to make it easier to spot errors
- update test dependencies
- use the same python version for pre-commit
- update docker collection and its dependencies
  • Loading branch information
ssbarnea authored Oct 28, 2024
1 parent 860adb6 commit f58ac30
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions .config/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ansible-lint >= 6.12.1
black
check-jsonschema
coverage[toml]
docker >= 7.1.0 # testing
filelock >= 3.9.0
mypy
pexpect >= 4.8.0, < 5
Expand Down
2 changes: 1 addition & 1 deletion .config/requirements.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ansible-compat >= 24.6.1
ansible-core >= 2.12.10
ansible-core >= 2.15.0
click >= 8.0, < 9
click-help-colors
enrich >= 1.2.7
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
tox:
uses: ansible/team-devtools/.github/workflows/tox.yml@main
with:
default_python: "3.10" # for lint
other_names_also: "eco"
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ci:
autoupdate_commit_msg: "chore: pre-commit autoupdate"
autoupdate_schedule: monthly
autofix_commit_msg: "chore: auto fixes from pre-commit.com hooks"
default_language_version:
python: python3.10 # minimal we support officially for consistent results

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -98,7 +100,7 @@ repos:
- wcmatch

- repo: https://github.com/pre-commit/mirrors-mypy.git
rev: v1.11.2
rev: v1.13.0
hooks:
- id: mypy
additional_dependencies:
Expand Down Expand Up @@ -133,7 +135,6 @@ repos:
--strip-extras
--output-file=.config/constraints.txt pyproject.toml
files: ^.config\/.*requirements.*$
language_version: "3.10" # minimal we support officially
- repo: https://github.com/ansible/ansible-lint
rev: v24.9.2
hooks:
Expand Down
2 changes: 1 addition & 1 deletion collections/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
collections:
- name: community.crypto
- name: community.docker
version: ">=3.10.2"
version: ">=3.10.4"
- name: containers.podman
- name: kubernetes.core
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ cache_dir = "./.cache/.mypy"
# To ensure that calling `mypy .` produces desired results (vscode)
exclude = ["build"]
files = ["src", "tests"]
python_version = "3.10"
strict = true

[[tool.mypy.overrides]]
Expand All @@ -92,6 +93,7 @@ baseline = ".config/pydoclint-baseline.txt"
check-return-types = false
check-yield-types = false
exclude = '\.cache|\.git|\.tox|build|out|venv'
quiet = true # no need to print out the files being checked
should-document-private-class-attributes = true
show-filenames-in-every-violation-message = true
skip-checking-short-docstrings = false
Expand Down Expand Up @@ -354,6 +356,9 @@ verbosity_assertions = 2
[tool.ruff]
builtins = ["__"]
cache-dir = "./.cache/.ruff"
external = [
"DOC" # pydoclint
]
fix = true
line-length = 100
target-version = "py310"
Expand Down
4 changes: 1 addition & 3 deletions src/molecule/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@


if TYPE_CHECKING:
from typing import Self

from molecule.config import Config
from molecule.scenario import Scenario

Expand All @@ -55,7 +53,7 @@ def __init__(
self._scenario_name = scenario_name
self._scenarios = self.all

def __iter__(self) -> Self:
def __iter__(self) -> Scenarios:
"""Make object iterable.
Returns:
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ def is_subset(subset, superset): # type: ignore[no-untyped-def] # noqa: ANN001
return subset == superset


@pytest.fixture(autouse=True)
def _no_color(monkeypatch: pytest.MonkeyPatch) -> None:
"""Disable coloring output.
Args:
monkeypatch: pytest.MonkeyPatch.
"""
# Analyzing output with no color is much easier. Tests that need to test for
# color output, should override the value.
monkeypatch.setitem(os.environ, "NO_COLOR", "1")
monkeypatch.delitem(os.environ, "PY_COLORS", raising=False)
monkeypatch.delitem(os.environ, "ANSIBLE_FORCE_COLOR", raising=False)
monkeypatch.delitem(os.environ, "FORCE_COLOR", raising=False)


@pytest.fixture()
def resources_folder_path() -> Path:
"""Return the path to the resources folder.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
collections:
- name: community.docker
version: ">=3.10.2"
version: ">=3.10.4"
3 changes: 2 additions & 1 deletion tests/integration/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,5 @@ def test_smoke(monkeypatch: pytest.MonkeyPatch, test_fixture_dir: Path) -> None:
"""
monkeypatch.chdir(test_fixture_dir)
command = ["molecule", "test", "--scenario-name", "smoke"]
assert run_command(command).returncode == 0
result = run_command(command)
assert result.returncode == 0, result
4 changes: 2 additions & 2 deletions tests/unit/model/v2/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

if TYPE_CHECKING:
from pathlib import Path
from typing import Any, LiteralString
from typing import Any


@pytest.fixture(name="molecule_file")
Expand Down Expand Up @@ -69,7 +69,7 @@ def config(molecule_file: Path, request: pytest.FixtureRequest) -> dict[str, Any


@pytest.fixture()
def _model_platforms_delegated_section_data() -> LiteralString:
def _model_platforms_delegated_section_data() -> str:
return """
---
platforms:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def test_markup_detection_pycolors0(monkeypatch): # type: ignore[no-untyped-def


def test_markup_detection_pycolors1(monkeypatch): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, D103
monkeypatch.delenv("NO_COLOR", raising=False)
monkeypatch.setenv("PY_COLORS", "1")
assert should_do_markup()

Expand Down

0 comments on commit f58ac30

Please sign in to comment.