-
Notifications
You must be signed in to change notification settings - Fork 222
chore: add typing hints to pytest components #1478
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
base: master
Are you sure you want to change the base?
Changes from all commits
de83086
29565e5
6bcd2f4
66e9a5d
951ff7e
593290c
995697e
39a2460
83dfee8
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
partial |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
from .fixtures import pytest_addoption, env, target, strategy | ||
from .hooks import pytest_configure, pytest_collection_modifyitems, pytest_cmdline_main, pytest_runtest_setup | ||
|
||
__all__ = [ | ||
"pytest_addoption", | ||
"env", | ||
"target", | ||
"strategy", | ||
"pytest_configure", | ||
"pytest_collection_modifyitems", | ||
"pytest_cmdline_main", | ||
"pytest_runtest_setup", | ||
] | ||
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( | ||
'--lg-env', | ||
|
@@ -52,7 +58,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. | ||
""" | ||
|
@@ -69,7 +75,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 | ||
|
@@ -112,7 +119,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() | ||
|
@@ -123,13 +130,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?