|
|
@ -15,6 +15,7 @@
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
@ -27,12 +28,17 @@ from . import ui_tests
|
|
|
|
from .device_handler import BackgroundDeviceHandler
|
|
|
|
from .device_handler import BackgroundDeviceHandler
|
|
|
|
from .ui_tests.reporting import testreport
|
|
|
|
from .ui_tests.reporting import testreport
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
|
|
|
from _pytest.config import Config
|
|
|
|
|
|
|
|
from _pytest.config.argparsing import Parser
|
|
|
|
|
|
|
|
from _pytest.terminal import TerminalReporter
|
|
|
|
|
|
|
|
|
|
|
|
# So that we see details of failed asserts from this module
|
|
|
|
# So that we see details of failed asserts from this module
|
|
|
|
pytest.register_assert_rewrite("tests.common")
|
|
|
|
pytest.register_assert_rewrite("tests.common")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def _raw_client(request):
|
|
|
|
def _raw_client(request: pytest.FixtureRequest) -> TrezorClientDebugLink:
|
|
|
|
path = os.environ.get("TREZOR_PATH")
|
|
|
|
path = os.environ.get("TREZOR_PATH")
|
|
|
|
interact = int(os.environ.get("INTERACT", 0))
|
|
|
|
interact = int(os.environ.get("INTERACT", 0))
|
|
|
|
if path:
|
|
|
|
if path:
|
|
|
@ -56,7 +62,9 @@ def _raw_client(request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def client(request, _raw_client):
|
|
|
|
def client(
|
|
|
|
|
|
|
|
request: pytest.FixtureRequest, _raw_client: TrezorClientDebugLink
|
|
|
|
|
|
|
|
) -> TrezorClientDebugLink:
|
|
|
|
"""Client fixture.
|
|
|
|
"""Client fixture.
|
|
|
|
|
|
|
|
|
|
|
|
Every test function that requires a client instance will get it from here.
|
|
|
|
Every test function that requires a client instance will get it from here.
|
|
|
@ -156,20 +164,20 @@ def client(request, _raw_client):
|
|
|
|
_raw_client.close()
|
|
|
|
_raw_client.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_sessionstart(session):
|
|
|
|
def pytest_sessionstart(session: pytest.Session) -> None:
|
|
|
|
ui_tests.read_fixtures()
|
|
|
|
ui_tests.read_fixtures()
|
|
|
|
if session.config.getoption("ui") == "test":
|
|
|
|
if session.config.getoption("ui") == "test":
|
|
|
|
testreport.clear_dir()
|
|
|
|
testreport.clear_dir()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _should_write_ui_report(exitstatus):
|
|
|
|
def _should_write_ui_report(exitstatus: pytest.ExitCode) -> bool:
|
|
|
|
# generate UI report and check missing only if pytest is exitting cleanly
|
|
|
|
# generate UI report and check missing only if pytest is exitting cleanly
|
|
|
|
# I.e., the test suite passed or failed (as opposed to ctrl+c break, internal error,
|
|
|
|
# I.e., the test suite passed or failed (as opposed to ctrl+c break, internal error,
|
|
|
|
# etc.)
|
|
|
|
# etc.)
|
|
|
|
return exitstatus in (pytest.ExitCode.OK, pytest.ExitCode.TESTS_FAILED)
|
|
|
|
return exitstatus in (pytest.ExitCode.OK, pytest.ExitCode.TESTS_FAILED)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_sessionfinish(session, exitstatus):
|
|
|
|
def pytest_sessionfinish(session: pytest.Session, exitstatus: pytest.ExitCode) -> None:
|
|
|
|
if not _should_write_ui_report(exitstatus):
|
|
|
|
if not _should_write_ui_report(exitstatus):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
@ -183,7 +191,9 @@ def pytest_sessionfinish(session, exitstatus):
|
|
|
|
ui_tests.write_fixtures(missing)
|
|
|
|
ui_tests.write_fixtures(missing)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_terminal_summary(terminalreporter, exitstatus, config):
|
|
|
|
def pytest_terminal_summary(
|
|
|
|
|
|
|
|
terminalreporter: "TerminalReporter", exitstatus: pytest.ExitCode, config: "Config"
|
|
|
|
|
|
|
|
) -> None:
|
|
|
|
println = terminalreporter.write_line
|
|
|
|
println = terminalreporter.write_line
|
|
|
|
println("")
|
|
|
|
println("")
|
|
|
|
|
|
|
|
|
|
|
@ -213,7 +223,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):
|
|
|
|
println("")
|
|
|
|
println("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
|
|
def pytest_addoption(parser: "Parser") -> None:
|
|
|
|
parser.addoption(
|
|
|
|
parser.addoption(
|
|
|
|
"--ui",
|
|
|
|
"--ui",
|
|
|
|
action="store",
|
|
|
|
action="store",
|
|
|
@ -229,7 +239,7 @@ def pytest_addoption(parser):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_configure(config):
|
|
|
|
def pytest_configure(config: "Config") -> None:
|
|
|
|
"""Called at testsuite setup time.
|
|
|
|
"""Called at testsuite setup time.
|
|
|
|
|
|
|
|
|
|
|
|
Registers known markers, enables verbose output if requested.
|
|
|
|
Registers known markers, enables verbose output if requested.
|
|
|
@ -253,7 +263,7 @@ def pytest_configure(config):
|
|
|
|
log.enable_debug_output()
|
|
|
|
log.enable_debug_output()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_runtest_setup(item):
|
|
|
|
def pytest_runtest_setup(item: pytest.Item) -> None:
|
|
|
|
"""Called for each test item (class, individual tests).
|
|
|
|
"""Called for each test item (class, individual tests).
|
|
|
|
|
|
|
|
|
|
|
|
Ensures that altcoin tests are skipped, and that no test is skipped on
|
|
|
|
Ensures that altcoin tests are skipped, and that no test is skipped on
|
|
|
@ -267,7 +277,7 @@ def pytest_runtest_setup(item):
|
|
|
|
pytest.skip("Skipping altcoin test")
|
|
|
|
pytest.skip("Skipping altcoin test")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_runtest_teardown(item):
|
|
|
|
def pytest_runtest_teardown(item: pytest.Item) -> None:
|
|
|
|
"""Called after a test item finishes.
|
|
|
|
"""Called after a test item finishes.
|
|
|
|
|
|
|
|
|
|
|
|
Dumps the current UI test report HTML.
|
|
|
|
Dumps the current UI test report HTML.
|
|
|
@ -277,7 +287,7 @@ def pytest_runtest_teardown(item):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
|
|
|
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
|
|
|
def pytest_runtest_makereport(item, call):
|
|
|
|
def pytest_runtest_makereport(item: pytest.Item, call) -> None:
|
|
|
|
# Make test results available in fixtures.
|
|
|
|
# Make test results available in fixtures.
|
|
|
|
# See https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures
|
|
|
|
# See https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures
|
|
|
|
# The device_handler fixture uses this as 'request.node.rep_call.passed' attribute,
|
|
|
|
# The device_handler fixture uses this as 'request.node.rep_call.passed' attribute,
|
|
|
@ -288,7 +298,9 @@ def pytest_runtest_makereport(item, call):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
@pytest.fixture
|
|
|
|
def device_handler(client, request):
|
|
|
|
def device_handler(
|
|
|
|
|
|
|
|
client: TrezorClientDebugLink, request: pytest.FixtureRequest
|
|
|
|
|
|
|
|
) -> None:
|
|
|
|
device_handler = BackgroundDeviceHandler(client)
|
|
|
|
device_handler = BackgroundDeviceHandler(client)
|
|
|
|
yield device_handler
|
|
|
|
yield device_handler
|
|
|
|
|
|
|
|
|
|
|
@ -299,5 +311,5 @@ def device_handler(client, request):
|
|
|
|
|
|
|
|
|
|
|
|
# if test finished, make sure all background tasks are done
|
|
|
|
# if test finished, make sure all background tasks are done
|
|
|
|
finalized_ok = device_handler.check_finalize()
|
|
|
|
finalized_ok = device_handler.check_finalize()
|
|
|
|
if request.node.rep_call.passed and not finalized_ok:
|
|
|
|
if request.node.rep_call.passed and not finalized_ok: # type: ignore [rep_call must exist]
|
|
|
|
raise RuntimeError("Test did not check result of background task")
|
|
|
|
raise RuntimeError("Test did not check result of background task")
|
|
|
|