Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and

## Unreleased

- [#868](https://github.com/pytask-dev/pytask/pull/868) resets the global marker
configuration during unconfigure so `--strict-markers` no longer leaks into later
marker access in the same process.
- [#837](https://github.com/pytask-dev/pytask/pull/837) skips incremental live
rendering on non-interactive output while preserving the final build table and
live-manager lifecycle.
Expand Down
6 changes: 6 additions & 0 deletions src/_pytask/mark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
MARK_GEN.config = config


@hookimpl
def pytask_unconfigure() -> None:
"""Reset marker state after pytask is done."""
MARK_GEN.config = None


@hookimpl
def pytask_post_parse(config: dict[str, Any]) -> None:
config["markers"] = parse_markers(config["markers"])
Expand Down
21 changes: 21 additions & 0 deletions tests/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,27 @@ def task_write_text(): ...
assert "Unknown pytask.mark.unknown" in result.output


@pytest.mark.filterwarnings("ignore:Unknown pytask\\.mark\\.foo")
def test_strict_markers_do_not_leak_after_unconfigure(runner, tmp_path):
source = """
from pytask import mark

@mark.unknown
def task_write_text(): ...
"""
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
result = runner.invoke(cli, [tmp_path.as_posix(), "--strict-markers"])
assert result.exit_code == ExitCode.COLLECTION_FAILED

# If the strict config leaked through MARK_GEN.config, this unknown marker would
# raise instead of warning and returning a MarkDecorator.
md = pytask.mark.foo(1, "2", three=3)

assert md.name == "foo"
assert md.args == (1, "2")
assert md.kwargs == {"three": 3}


@pytest.mark.parametrize("name", ["parametrize", "depends_on", "produces", "task"])
def test_error_with_deprecated_markers(runner, tmp_path, name):
source = f"""
Expand Down