Skip to content

Commit

Permalink
NTestRun -> CtxTestRun
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaerki committed Feb 4, 2025
1 parent ac251f3 commit 3be1127
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/introduction/30_flightlevel_pytest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ This file configures pytest and contains many important hooks.

.. rubric:: This function will setup and tear down octoprobe

.. autofunction:: tests.conftest::session_setup()
.. autofunction:: tests.conftest::ctxtestrun()
:no-index:


Expand Down
8 changes: 4 additions & 4 deletions docs/showcase/20_write_pytests/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ References to to source code

* Sessions setup: pytest fixture

.. autofunction:: tests.conftest::session_setup
.. autofunction:: tests.conftest::ctxtestrun
:no-index:

* Sessions setup: Build the software
Expand All @@ -113,10 +113,10 @@ References to to source code

* Session setup: Install the firmware

.. automethod:: octoprobe.octoprobe::NTestRun.function_prepare_dut()
.. automethod:: octoprobe.octoprobe::CtxTestRun.function_prepare_dut()
:no-index:

.. automethod:: octoprobe.octoprobe::NTestRun.function_setup_dut_flash()
.. automethod:: octoprobe.octoprobe::CtxTestRun.function_setup_dut_flash()
:no-index:

* Function setup: pytest fixture
Expand All @@ -126,7 +126,7 @@ References to to source code

* Function setup: Set the relays

.. automethod:: octoprobe.octoprobe::NTestRun.setup_relays
.. automethod:: octoprobe.octoprobe::CtxTestRun.setup_relays
:no-index:


Expand Down
8 changes: 4 additions & 4 deletions testbed_showcase.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"python.testing.pytestArgs": [
"-v",
"-s",
"--git-micropython-tests=https://github.com/dpgeorge/micropython.git@tests-full-test-runner",
// "--firmware-json=${workspaceFolder}/pytest_args_firmware_RPI_PICO_v1.23.0.json",
// "--firmware-json=${workspaceFolder}/pytest_args_firmware_RPI_PICO2_v1.24.0.json",
"--firmware-build-url=https://github.com/micropython/[email protected]",
// "--git-micropython-tests=https://github.com/dpgeorge/micropython.git@tests-full-test-runner",
// "--firmware=${workspaceFolder}/pytest_args_firmware_RPI_PICO_v1.23.0.json",
// "--firmware=${workspaceFolder}/pytest_args_firmware_RPI_PICO2_v1.24.0.json",
"--firmware=https://github.com/micropython/[email protected]",
"tests"
],
"python.testing.cwd": "${workspaceFolder}",
Expand Down
35 changes: 16 additions & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections.abc import Iterator

import pytest
from octoprobe.octoprobe import NTestRun
from octoprobe.octoprobe import CtxTestRun
from octoprobe.util_firmware_spec import FirmwareSpecBase
from octoprobe.util_pytest import util_logging
from octoprobe.util_pytest.util_resultdir import ResultsDir
Expand Down Expand Up @@ -181,7 +181,7 @@ def inner() -> Iterator[TentacleShowcase]:
return list(inner())


class NTestRunShowcase(NTestRun):
class CtxTestrunShowcase(CtxTestRun):
def __init__(
self,
connected_tentacles: typing.Sequence[TentacleShowcase],
Expand All @@ -197,14 +197,12 @@ def session_teardown(self) -> None:
self.udev_poller.close()


# TODO: Rename 'session_setup' -> session_context
# TODO: NTestRunShowcase -> CtxTestrunShowcase
@fixture(scope="session", autouse=True)
def session_setup(request: pytest.FixtureRequest) -> Iterator[NTestRunShowcase]:
def ctxtestrun(request: pytest.FixtureRequest) -> Iterator[CtxTestrunShowcase]:
"""
Setup and teardown octoprobe and all connected tentacles.
Now we loop over all tests an return for every test a `NTestRun` structure.
Now we loop over all tests an return for every test a `CtxTestRun` structure.
Using this structure, the test find there tentacles, git-repos etc.
"""
assert TESTBED is not None
Expand All @@ -224,7 +222,7 @@ def session_setup(request: pytest.FixtureRequest) -> Iterator[NTestRunShowcase]:
)
args_firmware.setup()

_testrun = NTestRunShowcase(
_testrun = CtxTestrunShowcase(
connected_tentacles=TESTBED.tentacles,
args_firmware=args_firmware,
)
Expand All @@ -236,10 +234,9 @@ def session_setup(request: pytest.FixtureRequest) -> Iterator[NTestRunShowcase]:
_testrun.session_teardown()


# TODO: session_setup -> ctxtestrun_showcase
@fixture(scope="function", autouse=True)
def setup_tentacles(
session_setup: NTestRunShowcase, # pylint: disable=W0621:redefined-outer-name
ctxtestrun: CtxTestrunShowcase, # pylint: disable=W0621:redefined-outer-name
required_futs: tuple[EnumFut], # pylint: disable=W0621:redefined-outer-name
active_tentacles: list[
TentacleShowcase
Expand All @@ -262,7 +259,7 @@ def setup_tentacles(
* Resets the relays.
:param testrun: The structure created by `testrun()`
:type testrun: NTestRun
:type testrun: CtxTestRun
"""
if len(active_tentacles) == 0:
# No tentacle has been specified: This is just a normal pytest.
Expand All @@ -285,22 +282,22 @@ def duration_text(duration_s: float | None = None) -> str:
mpbuild_artifacts = testresults_directory.directory_top / SUBDIR_MPBUILD
mpbuild_artifacts.mkdir(parents=True, exist_ok=True)
for tentacle in active_tentacles:
session_setup.args_firmware.build_firmware(
ctxtestrun.args_firmware.build_firmware(
tentacle=tentacle,
mpbuild_artifacts=mpbuild_artifacts,
)
session_setup.function_prepare_dut(tentacle=tentacle)
session_setup.function_setup_infra(
udev_poller=session_setup.udev_poller,
ctxtestrun.function_prepare_dut(tentacle=tentacle)
ctxtestrun.function_setup_infra(
udev_poller=ctxtestrun.udev_poller,
tentacle=tentacle,
)
session_setup.function_setup_dut_flash(
udev_poller=session_setup.udev_poller,
ctxtestrun.function_setup_dut_flash(
udev_poller=ctxtestrun.udev_poller,
tentacle=tentacle,
directory_logs=mpbuild_artifacts,
)

session_setup.setup_relays(futs=required_futs, tentacles=active_tentacles)
ctxtestrun.setup_relays(futs=required_futs, tentacles=active_tentacles)
logger.info(
f"TEST BEGIN {duration_text()} {testresults_directory.test_nodeid}"
)
Expand All @@ -315,7 +312,7 @@ def duration_text(duration_s: float | None = None) -> str:
f"TEST TEARDOWN {duration_text()} {testresults_directory.test_nodeid}"
)
try:
session_setup.function_teardown(active_tentacles=active_tentacles)
ctxtestrun.function_teardown(active_tentacles=active_tentacles)
except Exception as e:
logger.exception(e)
logger.info(
Expand Down Expand Up @@ -349,7 +346,7 @@ def pytest_sessionstart(session: pytest.Session):
util_logging.init_logging()
util_logging.Logs(DIRECTORY_TESTRESULTS_DEFAULT)

usb_tentacles = NTestRun.session_powercycle_tentacles()
usb_tentacles = CtxTestRun.session_powercycle_tentacles()
tentacles: list[TentacleShowcase] = []
for usb_tentacle in usb_tentacles:
serial = usb_tentacle.serial
Expand Down

0 comments on commit 3be1127

Please sign in to comment.