Skip to content

refactor pyreverse tests to use temporary directory #8529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2023
Merged
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
22 changes: 7 additions & 15 deletions tests/pyreverse/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import os
from collections.abc import Iterator
from difflib import unified_diff
from pathlib import Path
from unittest.mock import Mock

import pytest
from pytest import MonkeyPatch

from pylint.pyreverse.diadefslib import DefaultDiadefGenerator, DiadefsHandler
from pylint.pyreverse.inspector import Linker, Project
Expand Down Expand Up @@ -71,6 +73,11 @@ def _file_lines(path: str) -> list[str]:
return [line for line in lines if line]


@pytest.fixture(autouse=True)
def change_to_temp_dir(monkeypatch: MonkeyPatch, tmp_path: Path) -> None:
monkeypatch.chdir(tmp_path)


@pytest.fixture()
def setup_dot(
default_config: PyreverseConfig, get_project: GetProjectCallable
Expand Down Expand Up @@ -146,19 +153,6 @@ def _setup(
diagram.extract_relationships()
writer.write(dd)
yield
for fname in (
DOT_FILES
+ COLORIZED_DOT_FILES
+ NO_STANDALONE_FILES
+ PUML_FILES
+ COLORIZED_PUML_FILES
+ MMD_FILES
+ HTML_FILES
):
try:
os.remove(fname)
except FileNotFoundError:
continue


@pytest.mark.usefixtures("setup_dot")
Expand Down Expand Up @@ -240,5 +234,3 @@ def test_package_name_with_slash(default_config: PyreverseConfig) -> None:
writer.write([obj])

assert os.path.exists("test_package_name_with_slash_.dot")
# remove the generated file
os.remove("test_package_name_with_slash_.dot")