Verified Commit c4e16a31 authored by Karel Koci's avatar Karel Koci 🤘
Browse files

tests: decrease scope of fixture to just package

The scope of session reaches not only tests but also selftests and in
general we want to keep those two separate thus these fixtures should be
limited by package they are defined in.

In some cases this is rather extension because for some reason for
example client_board was defined with module scope. The effect of that
was that client was been reconnected for every module. Making that for
whole package saves a little bit of time. The original idea was to make
sure that we are connected but if ever test plays with local network it
on teardown it has to restore original settings and thus it should make
original connection available again.
parent 98467dd4
......@@ -71,7 +71,7 @@ def pytest_runtest_setup(item):
########################################################################################################################
# Resources shared among all tests #####################################################################################
@pytest.fixture(name="board", scope="session")
@pytest.fixture(name="board", scope="package")
def fixture_board(request):
"""Brings board on. Nothing else.
This is top most fixture for board. It returns board handle.
......@@ -82,14 +82,14 @@ def fixture_board(request):
return brd
@pytest.fixture(name="lxd", scope="session")
@pytest.fixture(name="lxd", scope="package")
def fixture_lxd():
"""Provides access to nsfarm.lxd.LXDConnection instance.
"""
return nsfarm.lxd.LXDConnection()
@pytest.fixture(name="device_map", scope="session")
@pytest.fixture(name="device_map", scope="package")
def fixture_device_map(request):
"""Provides easier access to device map generated by target.
"""
......@@ -99,7 +99,7 @@ def fixture_device_map(request):
########################################################################################################################
# Boot and setup fixtures ##############################################################################################
@pytest.fixture(name="board_serial", scope="session")
@pytest.fixture(name="board_serial", scope="package")
def fixture_board_serial(request, lxd, board):
"""Boot board to Shell.
Provides instance of nsfarm.cli.Shell()
......@@ -108,7 +108,7 @@ def fixture_board_serial(request, lxd, board):
return board.bootup(lxd, request.config.target_branch)
@pytest.fixture(name="board_root_password", scope="session")
@pytest.fixture(name="board_root_password", scope="package")
def fixture_board_root_password(request, board_serial):
"""Sets random password for user root.
Returns configured random password
......@@ -119,7 +119,7 @@ def fixture_board_root_password(request, board_serial):
return password
@pytest.fixture(name="client_board", scope="module")
@pytest.fixture(name="client_board", scope="package")
def fixture_client_board(board, board_serial, board_root_password, lan1_client):
"""Starts client on LAN1 and connect to board using SSH.
Provides instance of nsfarm.cli.Shell() connected to board shell using SSH trough client container.
......@@ -146,7 +146,7 @@ def fixture_client_board(board, board_serial, board_root_password, lan1_client):
########################################################################################################################
# Common containers ####################################################################################################
@pytest.fixture(name="isp_container", scope="module")
@pytest.fixture(name="isp_container", scope="package")
def fixture_isp_container(lxd, device_map):
"""Minimal ISP container used to provide the Internet access for the most of the tests.
"""
......@@ -155,7 +155,7 @@ def fixture_isp_container(lxd, device_map):
yield container
@pytest.fixture(name="lan1_client", scope="module")
@pytest.fixture(name="lan1_client", scope="package")
def fixture_lan1_client(lxd, device_map):
"""Starts client container on LAN1 and provides it.
"""
......@@ -167,7 +167,7 @@ def fixture_lan1_client(lxd, device_map):
########################################################################################################################
# Standard configuration ###############################################################################################
@pytest.fixture(name="board_wan", scope="module")
@pytest.fixture(name="board_wan", scope="package")
def fixture_board_wan(client_board, isp_container):
"""Basic config Internet configuration usable for most of the tests.
This configures static IP through ips_container.
......@@ -196,7 +196,7 @@ RWS0FA1Nun7JDt0L8SjRsDRJGDvUCdDdfs21feiW+qpGHNMhVZ930hky
"""
@pytest.fixture(name="updater_branch", scope="module")
@pytest.fixture(name="updater_branch", scope="package")
def fixture_updater_branch(request, client_board):
"""Setup target branch to updater.
This is required as not in all branches is the target updater branch the build branch.
......@@ -221,7 +221,7 @@ def pytest_report_header(config):
)
@pytest.fixture(scope="session", autouse=True)
@pytest.fixture(scope="package", autouse=True)
def log_target_to_testsuite_property(request, record_testsuite_property):
"""Include target and branch in test results as global properties.
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment