From 733eeb27581ee6fc2a9c2d79d7b002127bde85f1 Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Wed, 8 Nov 2023 17:06:33 -0800 Subject: Change to a temporary directory before running tests Some tests will throw errors if files or directories with certain names exist in the current working directory when pytest is run, such as Example.jpg. --- tests/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/conftest.py b/tests/conftest.py index 5fccfc0..8b1fea9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,12 +17,25 @@ """Define fixtures used across all tests in this folder.""" +from os import chdir +from pathlib import Path + import pytest import requests_mock as rm from wikiget.file import File +@pytest.fixture(autouse=True) +def _chdir_to_tmp_dir(tmp_path: Path) -> None: + """Change to a temporary directory before running tests. + + :param tmp_path: temporary path object + :type tmp_path: Path + """ + chdir(tmp_path) + + @pytest.fixture() def file_with_name() -> File: """Create a test File with only a filename. -- cgit v1.2.3