diff --git a/tests/__init__.py b/tests/__init__.py index 05fd513..eeb1aac 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,6 +4,18 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# pyre-strict + +import importlib.resources import logging logging.disable() + + +def read_fixture(filepath: str) -> str: + return ( + importlib.resources.files(__package__) + .joinpath("fixtures") + .joinpath(filepath) + .read_text() + ) diff --git a/tests/test_branch_worker.py b/tests/test_branch_worker.py index f8cf38f..3b2dabb 100644 --- a/tests/test_branch_worker.py +++ b/tests/test_branch_worker.py @@ -6,8 +6,6 @@ # pyre-unsafe -import importlib.resources -import os import random import re import shutil @@ -51,6 +49,8 @@ init_pw_responses, ) +from . import read_fixture + TEST_REPO = "repo" TEST_REPO_URL = f"https://user:pass@127.0.0.1:0/org/{TEST_REPO}" @@ -104,12 +104,6 @@ } -def read_fixture(filepath: str) -> str: - with importlib.resources.path(__package__, "fixtures") as base: - with open(os.path.join(base, "fixtures", filepath)) as f: - return f.read() - - class BranchWorkerMock(BranchWorker): def __init__(self, *args: Any, **kwargs: Any) -> None: presets = { diff --git a/tests/test_github_logs.py b/tests/test_github_logs.py index e021634..c84c101 100644 --- a/tests/test_github_logs.py +++ b/tests/test_github_logs.py @@ -6,8 +6,6 @@ # pyre-unsafe -import importlib.resources -import os import unittest from aioresponses import aioresponses @@ -15,11 +13,7 @@ from kernel_patches_daemon.github_logs import BpfGithubLogExtractor, GithubFailedJobLog - -def read_fixture(filepath: str) -> str: - with importlib.resources.path(__package__, "fixtures") as base: - with open(os.path.join(base, "fixtures", filepath)) as f: - return f.read() +from . import read_fixture class MockWorkflowJob(WorkflowJob):