From 330ea6b1a28202eeb4bbd920aa68bd448736ae8c Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Mon, 24 Jun 2024 12:49:50 -0400 Subject: [PATCH] add temporary directory fixture for pytest --- tests/conftest.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..bdfc664 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,23 @@ +from pathlib import Path + +import pytest + + +def pytest_addoption(parser): + """Sets up optional argument to keep temporary testing directory.""" + parser.addoption( + "--keep-tmp", + action="store_true", + help="Keep temporary directory after testing. Useful for debugging.", + ) + + +@pytest.fixture(scope="class") +def pass_options(request): + """Adds optional argument to a test class.""" + request.cls.KEEP_TMP = request.config.getoption("--keep-tmp") + + +@pytest.fixture(scope="function", autouse=True) +def temp_output_dir(tmpdir_factory) -> Path: + return Path(tmpdir_factory.mktemp("tmp-"))