-
Notifications
You must be signed in to change notification settings - Fork 191
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
chore: add typing hints to pytest components #1478
base: master
Are you sure you want to change the base?
Changes from all commits
e2ed990
1d9061e
25431a7
d7b71f9
f3557d2
27ae643
a8f887c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
from .fixtures import pytest_addoption, env, target, strategy | ||
from .hooks import pytest_configure, pytest_collection_modifyitems, pytest_cmdline_main | ||
|
||
__all__ = [ | ||
"pytest_addoption", | ||
"env", | ||
"target", | ||
"strategy", | ||
"pytest_configure", | ||
"pytest_collection_modifyitems", | ||
"pytest_cmdline_main", | ||
] | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import os | ||
import subprocess | ||
from typing import Iterator | ||
|
||
import pytest | ||
|
||
from .. import Environment, Target | ||
from ..exceptions import NoResourceFoundError, NoDriverFoundError | ||
from ..strategy import Strategy | ||
from ..remote.client import UserError | ||
from ..resource.remote import RemotePlace | ||
from ..util.ssh import sshmanager | ||
|
@@ -12,7 +16,9 @@ | |
# pylint: disable=redefined-outer-name | ||
|
||
|
||
def pytest_addoption(parser): | ||
def pytest_addoption(parser: pytest.Parser, pluginmanager: pytest.PytestPluginManager) -> None: | ||
del pluginmanager # unused | ||
|
||
group = parser.getgroup('labgrid') | ||
group.addoption( | ||
'--env-config', | ||
|
@@ -57,7 +63,7 @@ def pytest_addoption(parser): | |
|
||
|
||
@pytest.fixture(scope="session") | ||
def env(request, record_testsuite_property): | ||
def env(request: pytest.FixtureRequest, record_testsuite_property) -> Iterator[Environment]: | ||
"""Return the environment configured in the supplied configuration file. | ||
It contains the targets contained in the configuration file. | ||
""" | ||
|
@@ -74,7 +80,8 @@ def env(request, record_testsuite_property): | |
try: | ||
target = env.get_target(target_name) | ||
except UserError as e: | ||
pytest.exit(e) | ||
pytest.exit(str(e)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change seems to be unrelated to typing? Or does it fix a bug? If so, best to put the bug-fixes first, in one or more separate commits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this fixes that the wrong type of the |
||
assert target, "could not get target from environment" | ||
try: | ||
remote_place = target.get_resource(RemotePlace, wait_avail=False) | ||
remote_name = remote_place.name | ||
|
@@ -117,7 +124,7 @@ def env(request, record_testsuite_property): | |
|
||
|
||
@pytest.fixture(scope="session") | ||
def target(env): | ||
def target(env: Environment) -> Target: | ||
"""Return the default target `main` configured in the supplied | ||
configuration file.""" | ||
target = env.get_target() | ||
|
@@ -128,13 +135,13 @@ def target(env): | |
|
||
|
||
@pytest.fixture(scope="session") | ||
def strategy(request, target): | ||
def strategy(request: pytest.FixtureRequest, target: Target) -> Strategy: | ||
"""Return the Strategy of the default target `main` configured in the | ||
supplied configuration file.""" | ||
try: | ||
strategy = target.get_driver("Strategy") | ||
strategy: Strategy = target.get_driver("Strategy") | ||
except NoDriverFoundError as e: | ||
pytest.exit(e) | ||
pytest.exit(str(e)) | ||
|
||
state = request.config.option.lg_initial_state | ||
if state is not None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in a separate commit?