Skip to content

Commit

Permalink
fix check_dut_asic_type fixture index error (sonic-net#14830)
Browse files Browse the repository at this point in the history
Updated the rand_one_dut_hostname and selected_rand_dut fixtures to
set rand_one_dut_hostname_var whenever needed, specifically in the case
the fixture is dynamically loaded. Removed old method of setting
rand_one_dut_hostname_var.
  • Loading branch information
dayouliu1 authored and sreejithsreekumaran committed Nov 15, 2024
1 parent ef1ea4a commit b53a5d0
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ def rand_one_dut_hostname(request):
"""
"""
global rand_one_dut_hostname_var
if rand_one_dut_hostname_var is None:
set_rand_one_dut_hostname(request)
return rand_one_dut_hostname_var


Expand All @@ -507,6 +509,8 @@ def rand_selected_dut(duthosts, rand_one_dut_hostname):
@pytest.fixture(scope="module")
def selected_rand_dut(request):
global rand_one_dut_hostname_var
if rand_one_dut_hostname_var is None:
set_rand_one_dut_hostname(request)
return rand_one_dut_hostname_var


Expand Down Expand Up @@ -1699,12 +1703,6 @@ def pytest_generate_tests(metafunc): # noqa E302
if dut_fixture_name and "selected_dut" in metafunc.fixturenames:
metafunc.parametrize("selected_dut", duts_selected, scope="module", indirect=True)

# When rand_one_dut_hostname used and select a dut for test, initialize rand_one_dut_hostname_var
# rand_one_dut_hostname and rand_selected_dut will use this variable for setup test case
# selected_rand_dut will use this variable for setup TACACS
if "rand_one_dut_hostname" in metafunc.fixturenames:
set_rand_one_dut_hostname(metafunc)

if "enum_dut_portname" in metafunc.fixturenames:
metafunc.parametrize("enum_dut_portname", generate_port_lists(metafunc, "all_ports"))

Expand Down

0 comments on commit b53a5d0

Please sign in to comment.