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

Add pytest-lazyfixture stubs #5745

Merged
merged 15 commits into from Jul 9, 2021
Merged

Conversation

kasium
Copy link
Contributor

@kasium kasium commented Jul 9, 2021

This change will add stubs for pytest-lazyfixture. It is particual useful for projects which type their tests and use pytest-lazyfixture.
The included functions and classes are the scope which can be considered documented by the module. Any other function is related to pytest hook implementations and are normally not called by an user.

Please note, that if a user uses 'pytest.lazy_fixture' these stubs will not work. As recommneded in TvoroG/pytest-lazy-fixture#51 the package needs to imported directly.

This change will add stubs for pytest-lazyfixture. It is particual useful for projects which type their tests and use pytest-lazyfixture.
The included functions and classes are the scope which can be considered documented by the module. Any other function is related to pytest hook implementations and are normally not called by an user.

Please note, that if a user uses 'pytest.lazy_fixture' these stubs will not work. As recommneded in TvoroG/pytest-lazy-fixture#51 the package needs to imported directly.
@kasium kasium marked this pull request as draft July 9, 2021 08:08
@kasium kasium marked this pull request as ready for review July 9, 2021 08:12
@kasium
Copy link
Contributor Author

kasium commented Jul 9, 2021

The tests are failing with

stubtest failed for Pillow
Traceback (most recent call last):
  File "/home/runner/work/typeshed/typeshed/tests/stubtest_third_party.py", line 147, in <module>
    main()
  File "/home/runner/work/typeshed/typeshed/tests/stubtest_third_party.py", line 143, in main
    run_stubtest(dist)
  File "/home/runner/work/typeshed/typeshed/tests/stubtest_third_party.py", line 115, in run_stubtest
    raise StubtestFailed from None
__main__.StubtestFailed
Error: Process completed with exit code 1.

No clue why this affects Pillow

@Akuli
Copy link
Collaborator

Akuli commented Jul 9, 2021

Please rename stubs/pytest-lazyfixture to stubs/pytest-lazy-fixture. It should match the name used with pip install, and pip install pytest-lazyfixture doesn't work.

@kasium
Copy link
Contributor Author

kasium commented Jul 9, 2021

done

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

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

  • Stubtest error is not related to this PR. See Fix stubtest PIL error #5746
  • Some functions are missing, such as sorted_by_dependency. Consider adding a module-level __getattr__ to mark the stub as incomplete.

stubs/pytest-lazyfixture/pytest-lazy-fixture.pyi Outdated Show resolved Hide resolved
@Akuli
Copy link
Collaborator

Akuli commented Jul 9, 2021

I merged our master branch to this branch to fix the PIL error. You will need to git pull before you can push more commits.

@kasium
Copy link
Contributor Author

kasium commented Jul 9, 2021

New Error:
stubs/pytest-lazyfixture/pytest_lazy_fixture.pyi:9: error: Overloaded function signatures 1 and 2 overlap with incompatible return types

Co-authored-by: Akuli <akuviljanen17@gmail.com>
@kasium
Copy link
Contributor Author

kasium commented Jul 9, 2021

Thanks a lot for all the help and explanations!

@Akuli
Copy link
Collaborator

Akuli commented Jul 9, 2021

I think the file should be named pytest_lazyfixture.pyi, so that you can import pytest_lazyfixture. The file name is what you import, and the directory name is what you pip install.

@kasium
Copy link
Contributor Author

kasium commented Jul 9, 2021

That makes sense :-)

@kasium
Copy link
Contributor Author

kasium commented Jul 9, 2021

@Akuli I have a question: So pytest-lazyfixture injects an attribute into pytest so that pytest.lazy_fixture is accessible. Is it possible to somehow reflect this in the stubs? Please note, that pytest is completely typed and I'm not sure if it's possible to merge type information

@Akuli
Copy link
Collaborator

Akuli commented Jul 9, 2021

That's not something we can do in typeshed, because we don't have pytest stubs. This would need to be added to pytest's __init__.py:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    import pytest_lazyfixture as lazyfixture

But then types-pytest-lazy-fixture would have to be installed whenever you type-check pytest code, so that wouldn't be great either. I think it's easiest to just not support it for now.

@Akuli Akuli merged commit c4a60ce into python:master Jul 9, 2021
@kasium
Copy link
Contributor Author

kasium commented Jul 9, 2021

Thanks a lot!

@kasium kasium deleted the pytest-lazyfixture-stubs branch July 9, 2021 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants