Skip to content

Commit d644e5e

Browse files
authored
Reset marker config during unconfigure (#868)
1 parent 2ba1f62 commit d644e5e

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
77

88
## Unreleased
99

10+
- [#868](https://github.com/pytask-dev/pytask/pull/868) resets the global marker
11+
configuration during unconfigure so `--strict-markers` no longer leaks into later
12+
marker access in the same process.
1013
- [#837](https://github.com/pytask-dev/pytask/pull/837) skips incremental live
1114
rendering on non-interactive output while preserving the final build table and
1215
live-manager lifecycle.

src/_pytask/mark/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
111111
MARK_GEN.config = config
112112

113113

114+
@hookimpl
115+
def pytask_unconfigure() -> None:
116+
"""Reset marker state after pytask is done."""
117+
MARK_GEN.config = None
118+
119+
114120
@hookimpl
115121
def pytask_post_parse(config: dict[str, Any]) -> None:
116122
config["markers"] = parse_markers(config["markers"])

tests/test_mark.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,27 @@ def task_write_text(): ...
355355
assert "Unknown pytask.mark.unknown" in result.output
356356

357357

358+
@pytest.mark.filterwarnings("ignore:Unknown pytask\\.mark\\.foo")
359+
def test_strict_markers_do_not_leak_after_unconfigure(runner, tmp_path):
360+
source = """
361+
from pytask import mark
362+
363+
@mark.unknown
364+
def task_write_text(): ...
365+
"""
366+
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
367+
result = runner.invoke(cli, [tmp_path.as_posix(), "--strict-markers"])
368+
assert result.exit_code == ExitCode.COLLECTION_FAILED
369+
370+
# If the strict config leaked through MARK_GEN.config, this unknown marker would
371+
# raise instead of warning and returning a MarkDecorator.
372+
md = pytask.mark.foo(1, "2", three=3)
373+
374+
assert md.name == "foo"
375+
assert md.args == (1, "2")
376+
assert md.kwargs == {"three": 3}
377+
378+
358379
@pytest.mark.parametrize("name", ["parametrize", "depends_on", "produces", "task"])
359380
def test_error_with_deprecated_markers(runner, tmp_path, name):
360381
source = f"""

0 commit comments

Comments
 (0)