Skip to content

Commit

Permalink
[chassisd][thermalctld] Set testing env var at top of file, not in se…
Browse files Browse the repository at this point in the history
…tup_function() (sonic-net#114)

Since these tests are run via unittest infrastructure, and not via Pytest, `setup_function()` is not the proper location to set these variables.
  • Loading branch information
jleveque authored Nov 15, 2020
1 parent 2dd3b95 commit 9df5da7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 3 additions & 6 deletions sonic-chassisd/tests/test_chassisd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
scripts_path = os.path.join(modules_path, "scripts")
sys.path.insert(0, modules_path)

os.environ["CHASSISD_UNIT_TESTING"] = "1"
load_source('chassisd', scripts_path + '/chassisd')
from chassisd import *


CHASSIS_MODULE_INFO_NAME_FIELD = 'name'
Expand All @@ -29,19 +32,13 @@
CHASSIS_INFO_CARD_NUM_FIELD = 'module_num'

def setup_function():
os.environ["CHASSISD_UNIT_TESTING"] = "1"

load_source('chassisd', scripts_path + '/chassisd')
from chassisd import *

ModuleUpdater.log_notice = MagicMock()
ModuleUpdater.log_warning = MagicMock()


def teardown_function():
ModuleUpdater.log_notice.reset()
ModuleUpdater.log_warning.reset()
os.environ["CHASSISD_UNIT_TESTING"] = "0"


def test_moduleupdater_check_valid_fields():
Expand Down
10 changes: 4 additions & 6 deletions sonic-thermalctld/tests/test_thermalctld.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
scripts_path = os.path.join(modules_path, "scripts")
sys.path.insert(0, modules_path)

os.environ["THERMALCTLD_UNIT_TESTING"] = "1"
load_source('thermalctld', scripts_path + '/thermalctld')
from thermalctld import *


TEMPER_INFO_TABLE_NAME = 'TEMPERATURE_INFO'

def setup_function():
os.environ["THERMALCTLD_UNIT_TESTING"] = "1"

load_source('thermalctld', scripts_path + '/thermalctld')
from thermalctld import *

FanStatus.log_notice = MagicMock()
FanStatus.log_warning = MagicMock()
FanUpdater.log_notice = MagicMock()
Expand All @@ -45,7 +44,6 @@ def teardown_function():
TemperatureStatus.log_warning.reset()
TemperatureUpdater.log_warning.reset()
TemperatureUpdater.log_warning.reset()
os.environ["THERMALCTLD_UNIT_TESTING"] = "0"


def test_fanstatus_set_presence():
Expand Down

0 comments on commit 9df5da7

Please sign in to comment.