Skip to content

Commit

Permalink
[pytest] Fix module import issue when running whole test suite (sonic…
Browse files Browse the repository at this point in the history
…-net#1642)

* [pytest] Fix module import issue when running whole test suite

When having multiple conftest, dir leading to this conftest has
to be Python package (presence of __init__.py.) Also, adding
pytest basedir to conftest.py

signed-off-by: Tamer Ahmed <[email protected]>
  • Loading branch information
tahmed-dev authored May 7, 2020
1 parent 9814959 commit f88cff2
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 14 deletions.
Empty file added tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/arp/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from args.wr_arp_args import add_wr_arp_args
from .args.wr_arp_args import add_wr_arp_args

# WR-ARP pytest arguments
def pytest_addoption(parser):
Expand Down
8 changes: 0 additions & 8 deletions tests/common/plugins/sanity_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
logger = logging.getLogger(__name__)


def pytest_addoption(parser):
"""Describe plugin specified options"""
parser.addoption("--skip_sanity", action="store_true", default=False,
help="Skip sanity check")
parser.addoption("--allow_recover", action="store_true", default=False,
help="Allow recovery attempt in sanity check in case of failure")


def _update_check_items(old_items, new_items, supported_items):
"""
@summary: Update the items to be performed in sanity check
Expand Down
16 changes: 15 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Adding pytest base dir to Python system path.
# This is required in order to import from common package including pytest_plugins within this file.
import site
from os.path import dirname, abspath
site.addsitedir(dirname(abspath(__file__)))

import sys
import os
import glob
Expand Down Expand Up @@ -85,17 +91,25 @@ def pytest_addoption(parser):
# test_vrf options
parser.addoption("--vrf_capacity", action="store", default=None, type=int, help="vrf capacity of dut (4-1000)")
parser.addoption("--vrf_test_count", action="store", default=None, type=int, help="number of vrf to be tested (1-997)")

############################
# test_techsupport options #
############################

parser.addoption("--loop_num", action="store", default=10, type=int,
help="Change default loop range for show techsupport command")
parser.addoption("--loop_delay", action="store", default=10, type=int,
help="Change default loops delay")
parser.addoption("--logs_since", action="store", type=int,
help="number of minutes for show techsupport command")

############################
# sanity_check options #
############################
parser.addoption("--skip_sanity", action="store_true", default=False,
help="Skip sanity check")
parser.addoption("--allow_recover", action="store_true", default=False,
help="Allow recovery attempt in sanity check in case of failure")


@pytest.fixture(scope="session", autouse=True)
def enhance_inventory(request):
Expand Down
Empty file added tests/platform/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/platform/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from common.fixtures.advanced_reboot import get_advanced_reboot
from args.advanced_reboot_args import add_advanced_reboot_args
from .args.advanced_reboot_args import add_advanced_reboot_args

@pytest.fixture(autouse=True, scope="module")
def skip_on_simx(duthost):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import random
import logging
from thermal_control_test_helper import *
from ..thermal_control_test_helper import *
from common.mellanox_data import SWITCH_MODELS
from minimum_table import MINIMUM_TABLE

Expand Down
2 changes: 1 addition & 1 deletion tests/platform/mellanox/test_thermal_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from common.mellanox_data import SWITCH_MODELS
from common.plugins.loganalyzer.loganalyzer import LogAnalyzer
from common.utilities import wait_until
from thermal_control_test_helper import *
from ..thermal_control_test_helper import *
from mellanox_thermal_control_test_helper import MockerHelper, AbnormalFanMocker

THERMAL_CONTROL_TEST_WAIT_TIME = 65
Expand Down
Empty file added tests/testbed_setup/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/testbed_setup/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from args.populate_fdb_args import add_populate_fdb_args
from .args.populate_fdb_args import add_populate_fdb_args
from common.fixtures.populate_fdb import populate_fdb

# FDB pytest arguments
Expand Down

0 comments on commit f88cff2

Please sign in to comment.