Skip to content

Commit

Permalink
[test] Use an empty pylintrc so tests to not depend on system's conf
Browse files Browse the repository at this point in the history
Closes #8342, but this does not fix the problem generically, all
tests should run independentely from the system's pylint configuration
  • Loading branch information
Pierre-Sassoulas committed Feb 26, 2023
1 parent e7ad3e6 commit df86a24
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 5 additions & 2 deletions tests/checkers/unittest_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,23 @@ def test_preferred_module(capsys: CaptureFixture[str]) -> None:
assert len(errors) == 0

@staticmethod
def test_allow_reexport_package(capsys: CaptureFixture[str]) -> None:
def test_allow_reexport_package(
empty_pylintrc: str, capsys: CaptureFixture[str]
) -> None:
"""Test --allow-reexport-from-package option."""

# Option disabled - useless-import-alias should always be emitted
Run(
[
f"{os.path.join(REGR_DATA, 'allow_reexport')}",
"--allow-reexport-from-package=no",
f"--rc-file={empty_pylintrc}",
"-sn",
],
exit=False,
)
output, errors = capsys.readouterr()
assert len(output.split("\n")) == 5, f"Expected 5 line breaks in:{output}"
assert len(output.split("\n")) == 7, f"Expected 5 line breaks in:{output}"
assert (
"__init__.py:1:0: C0414: Import alias does not rename original package (useless-import-alias)"
in output
Expand Down
16 changes: 13 additions & 3 deletions tests/config/pylint_config/test_pylint_config_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_writing_to_output_file(


def test_writing_minimal_file(
monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]
empty_pylintrc: str, monkeypatch: MonkeyPatch, capsys: CaptureFixture[str]
) -> None:
"""Check that we can write a minimal file."""
# Monkeypatch everything we don't want to check in this test
Expand All @@ -181,12 +181,22 @@ def test_writing_minimal_file(
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="NOTE:.*", category=UserWarning)
# Check not minimal has comments
Run(["generate", "--interactive"], exit=False)
conf = f"--rc-file={empty_pylintrc}"
Run(["generate", "--interactive", conf], exit=False)
captured = capsys.readouterr()
assert any(line.startswith("#") for line in captured.out.splitlines())

# Check minimal doesn't have comments and no default values
Run(["--accept-no-return-doc=y", "generate", "--interactive"], exit=False)
Run(
[
conf,
"--load-plugins=pylint.extensions.docparams",
"--accept-no-return-doc=y",
"generate",
"--interactive",
],
exit=False,
)
captured = capsys.readouterr()
assert not any(i.startswith("#") for i in captured.out.split("\n"))
assert "accept-no-return-doc" not in captured.out
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
HERE = Path(__file__).parent


@pytest.fixture()
def empty_pylintrc() -> str:
return str(HERE / "data/empty_pylintrc")


@pytest.fixture()
def tests_directory() -> Path:
return HERE
Expand Down

0 comments on commit df86a24

Please sign in to comment.