Skip to content
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

Refactor functional testutil in order to normalize later #5418

Conversation

Pierre-Sassoulas
Copy link
Member

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

The functional tests grow all the time and organizing them properly will become a problem soon. See possible follow up here: #5396 (comment)

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Maintenance Discussion or action around maintaining pylint or the dev workflow labels Nov 28, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.12.2 milestone Nov 28, 2021
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the refactor-functional-testutil-for-normalize-later branch from 51fc083 to 9b8ea92 Compare November 28, 2021 15:55
@coveralls
Copy link

coveralls commented Nov 28, 2021

Pull Request Test Coverage Report for Build 1515867452

  • 99 of 102 (97.06%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 93.642%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pylint/testutils/functional/find_functional_tests.py 14 15 93.33%
pylint/testutils/functional/test_file.py 53 55 96.36%
Totals Coverage Status
Change from base Build 1513600876: 0.1%
Covered Lines: 14065
Relevant Lines: 15020

πŸ’› - Coveralls

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to add some additional tests for the DeprecationWarning's to make sure this isn't breaking. We have been doing that for other DeprecationWarning's as well.

Think this is a good move to make!

pylint/testutils/functional/find_functional_tests.py Outdated Show resolved Hide resolved
pylint/testutils/functional/lint_module_output_update.py Outdated Show resolved Hide resolved
pylint/testutils/functional/lint_module_output_update.py Outdated Show resolved Hide resolved
pylint/testutils/functional/test_file.py Outdated Show resolved Hide resolved
pylint/testutils/functional_test_file.py Outdated Show resolved Hide resolved
tests/test_functional.py Outdated Show resolved Hide resolved

import pytest

from pylint.testutils import FunctionalTestFile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add an test to see if the deprecation warning triggers correctly when doing this import?
I think it might be better to add this in a with pytest.warns guard anyway as we will otherwise always trigger the warning ourselves.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to do that but I don't know what is triggering the deprecation warning, it's supposed to not ever be imported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if somebody uses the current way to import it? Doesn't that trigger the deprecation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well there's a warning when we launch the test at the beginning not when we re-import later in the test:

    with pytest.warns(DeprecationWarning) as records:
        from pylint.testutils.functional_test_file import FunctionalTestFile

Result in :

        with pytest.warns(DeprecationWarning) as records:
>           from pylint.testutils.functional_test_file import FunctionalTestFile
E           Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>,) was emitted. The list of emitted warnings is: [].

tests/testutils/test_functional_test_file.py:5: Failed
============================================================================================ warnings summary =============================================================================================
pylint/testutils/functional_test_file.py:18
  /home/pierre/pylint/pylint/testutils/functional_test_file.py:18: DeprecationWarning: 'pylint.testutils.functional_test_file' will be accessible from the 'pylint.testutils.functional' namespace in pylint 3.0.

Notice how the deprecation Warning is taunting us at the bottom πŸ˜„

Somehow there must be an import from this file that I can't seem to find.

tests/testutils/test_lint_module_output_update.py Outdated Show resolved Hide resolved
ChangeLog Outdated Show resolved Hide resolved
pylint/testutils/__init__.py Outdated Show resolved Hide resolved
pylint/testutils/functional/lint_module_output_update.py Outdated Show resolved Hide resolved
pylint/testutils/functional/test_file.py Outdated Show resolved Hide resolved
pylint/testutils/functional/test_file.py Outdated Show resolved Hide resolved
pylint/testutils/functional/test_file.py Outdated Show resolved Hide resolved
pylint/testutils/lint_module_test.py Outdated Show resolved Hide resolved
@Pierre-Sassoulas
Copy link
Member Author

I'm inclined to revert the typing here and keep it for another MR as the following error appear:

pylint/testutils/lint_module_test.py:60: error: Unsupported operand types for >= ("_version_info" and "List[str]")  [operator]
pylint/testutils/lint_module_test.py:60: note: Right operand is of type "Union[Tuple[int, ...], List[str]]"
pylint/testutils/lint_module_test.py:71: error: Argument 1 to "__import__" has incompatible type "Union[int, str]"; expected "str"  [arg-type]
pylint/testutils/lint_module_test.py:75: error: Argument 1 to "join" of "str" has incompatible type "List[Union[int, str]]"; expected "Iterable[str]"  [arg-type]
pylint/testutils/lint_module_test.py:78: error: Item "Tuple[int, ...]" of "Union[Tuple[int, ...], List[str]]" has no attribute "split"  [union-attr]
pylint/testutils/lint_module_test.py:78: error: Item "List[str]" of "Union[Tuple[int, ...], List[str]]" has no attribute "split"  [union-attr]
pylint/testutils/lint_module_test.py:84: error: Item "Tuple[int, ...]" of "Union[Tuple[int, ...], List[str]]" has no attribute "split"  [union-attr]
pylint/testutils/lint_module_test.py:84: error: Item "List[str]" of "Union[Tuple[int, ...], List[str]]" has no attribute "split"  [union-attr]
pylint/testutils/lint_module_test.py:93: error: Unsupported operand types for < ("_version_info" and "List[str]")  [operator]
pylint/testutils/lint_module_test.py:93: note: Right operand is of type "Union[Tuple[int, ...], List[str]]"
pylint/testutils/lint_module_test.py:94: error: Unsupported operand types for > ("_version_info" and "List[str]")  [operator]
pylint/testutils/lint_module_test.py:94: note: Right operand is of type "Union[Tuple[int, ...], List[str]]"

options in FunctionalTestFile are a dict and the refactor look like enough work for another MR.

@DanielNoord
Copy link
Collaborator

DanielNoord commented Nov 28, 2021

I'm inclined to revert the typing here and keep it for another MR as the following error appear:

pylint/testutils/lint_module_test.py:60: error: Unsupported operand types for >= ("_version_info" and "List[str]")  [operator]
pylint/testutils/lint_module_test.py:60: note: Right operand is of type "Union[Tuple[int, ...], List[str]]"
pylint/testutils/lint_module_test.py:71: error: Argument 1 to "__import__" has incompatible type "Union[int, str]"; expected "str"  [arg-type]
pylint/testutils/lint_module_test.py:75: error: Argument 1 to "join" of "str" has incompatible type "List[Union[int, str]]"; expected "Iterable[str]"  [arg-type]
pylint/testutils/lint_module_test.py:78: error: Item "Tuple[int, ...]" of "Union[Tuple[int, ...], List[str]]" has no attribute "split"  [union-attr]
pylint/testutils/lint_module_test.py:78: error: Item "List[str]" of "Union[Tuple[int, ...], List[str]]" has no attribute "split"  [union-attr]
pylint/testutils/lint_module_test.py:84: error: Item "Tuple[int, ...]" of "Union[Tuple[int, ...], List[str]]" has no attribute "split"  [union-attr]
pylint/testutils/lint_module_test.py:84: error: Item "List[str]" of "Union[Tuple[int, ...], List[str]]" has no attribute "split"  [union-attr]
pylint/testutils/lint_module_test.py:93: error: Unsupported operand types for < ("_version_info" and "List[str]")  [operator]
pylint/testutils/lint_module_test.py:93: note: Right operand is of type "Union[Tuple[int, ...], List[str]]"
pylint/testutils/lint_module_test.py:94: error: Unsupported operand types for > ("_version_info" and "List[str]")  [operator]
pylint/testutils/lint_module_test.py:94: note: Right operand is of type "Union[Tuple[int, ...], List[str]]"

options in FunctionalTestFile are a dict and the refactor look like enough work for another MR.

Could you try to see if this works?

if sys.version_info >= (3, 8):
    from typing import TypedDict
else:
    from typing_extensions import TypedDict

class TestFileOptions(TypedDict):
    min_pyver: Tuple[int, ...]
    max_pyver: Tuple[int, ...]
    min_pyver_end_position: Tuple[int, ...]
    requires: List[str]
    except_implementations: List[str]
    exclude_platforms: List[str]

...

self.options: TestFileOptions = {

I think that should do it? If not reverting might indeed be best 😒

@Pierre-Sassoulas
Copy link
Member Author

Could you try to see if this works?

Thanks, done in df20ded. It's too big for this MR but I started to cherry-pick on main and there's conflicts... so let's merge everything here.

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! We actually caught some "bugs" due to the typing πŸ˜„

pylint/testutils/functional/lint_module_output_update.py Outdated Show resolved Hide resolved
pylint/testutils/functional/lint_module_output_update.py Outdated Show resolved Hide resolved
tests/functional/f/fixme.rc Show resolved Hide resolved
pylint/testutils/functional/test_file.py Show resolved Hide resolved
conv = self._CONVERTERS.get(name, lambda v: v)

assert (
name in POSSIBLE_TEST_OPTIONS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestFileOptions.__annotations__ would also work, but I'm not sure if you're supposed to access it..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like typed dict, it's only marginally better than a dict. Might refactor that class later.

pylint/testutils/functional/test_file.py Show resolved Hide resolved
ChangeLog Show resolved Hide resolved
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the refactor-functional-testutil-for-normalize-later branch from 8135de0 to a2a66a6 Compare November 29, 2021 12:15
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.12.2, 2.13.0 Nov 29, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Blocked 🚧 Blocked by a particular issue label Nov 29, 2021
@CarliJoy
Copy link
Contributor

Why is this MR blocked?

@Pierre-Sassoulas
Copy link
Member Author

Why is this MR blocked?

Waiting for 2.12.2 to be released : #5418 (comment)

@Pierre-Sassoulas Pierre-Sassoulas removed the Blocked 🚧 Blocked by a particular issue label Dec 3, 2021
@Pierre-Sassoulas Pierre-Sassoulas merged commit 5bb0095 into pylint-dev:main Dec 3, 2021
@Pierre-Sassoulas Pierre-Sassoulas deleted the refactor-functional-testutil-for-normalize-later branch December 3, 2021 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Maintenance Discussion or action around maintaining pylint or the dev workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants