Skip to content

Commit

Permalink
[work-in-progress] Test pytest vs python
Browse files Browse the repository at this point in the history
Suggestion from pytest-dev/pytest#11138 (comment)

With 'pytest':
FAILED tests/test_precedence.py::test_package - AssertionError: E: 21: Module 'package.AudioTime' has no 'DECIMAL' member<function Equals.<locals>.<lambda> at 0x76c566741750>

With 'python tests/test_precedence.py':
Checked ['package.__init__'] successfully
Checked ['precedence_test'] successfully
Checked ['import_package_subpackage_module'] successfully
Checked ['pylint.checkers.__init__'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/classdoc_usage.py'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/module_global.py'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/decimal_inference.py'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/absimp/string.py'] successfully
Checked ['/home/pierre/pylint/tests/regrtest_data/bad_package'] successfully
  • Loading branch information
Pierre-Sassoulas committed May 1, 2024
1 parent 3812d0d commit 4cf3b21
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_precedence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from __future__ import annotations

import os
import sys
from collections.abc import Callable
from os.path import abspath, dirname, join

from pylint import checkers
from pylint.lint.pylinter import PyLinter
from pylint.testutils import GenericTestReporter

REGR_DATA = join(dirname(abspath(__file__)), "regrtest_data")
sys.path.insert(1, REGR_DATA)


def Equals(expected: str) -> Callable[[str], bool]:
return lambda got: got == expected


def test_package() -> None:
for file_names, check in [
(["package.__init__"], Equals("")),
(["precedence_test"], Equals("")),
(["import_package_subpackage_module"], Equals("")),
(["pylint.checkers.__init__"], lambda x: "__path__" not in x),
([join(REGR_DATA, "classdoc_usage.py")], Equals("")),
([join(REGR_DATA, "module_global.py")], Equals("")),
([join(REGR_DATA, "decimal_inference.py")], Equals("")),
([join(REGR_DATA, "absimp", "string.py")], Equals("")),
([join(REGR_DATA, "bad_package")], lambda x: "Unused import missing" in x),
]:

Check notice on line 31 in tests/test_precedence.py

View workflow job for this annotation

GitHub Actions / pylint

R6102

Consider using an in-place tuple instead of list
finalize_linter = PyLinter()
finalize_linter.set_reporter(GenericTestReporter())
checkers.initialize(finalize_linter)
os.environ.pop("PYLINTRC", None)
finalize_linter.reporter.finalize()
finalize_linter.check(file_names)
got = finalize_linter.reporter.finalize().strip()
assert check(got), str(got) + str(check)
print(f"Checked {file_names} successfully")


if __name__ == "__main__":
test_package()

0 comments on commit 4cf3b21

Please sign in to comment.