Skip to content

Commit

Permalink
[TEST][TVMC] Circumvent pytest Mock hijack of FILE argument
Browse files Browse the repository at this point in the history
A TVMCException will be generated by test_tune_rpc_tracker_parsing
test because FILE will be set by pytest to MagicMock(), which is not
a valid input. Since FILE is irrelevant for the test in question
circumvent the Mock hijack of FILE argument by setting FILE properly.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
  • Loading branch information
gromero committed Apr 14, 2022
1 parent 4cadbcf commit 2d2951a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/python/driver/tvmc/test_autotuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from unittest import mock

from os import path
from pathlib import Path

from tvm import autotvm
from tvm.driver import tvmc
Expand Down Expand Up @@ -163,9 +164,16 @@ def test_tune_tasks__invalid_tuner(onnx_mnist, tmpdir_factory):
def test_tune_rpc_tracker_parsing(mock_load_model, mock_tune_model, mock_auto_scheduler):
cli_args = mock.MagicMock()
cli_args.rpc_tracker = "10.0.0.1:9999"
# FILE is not used but it's set to a valid value here to avoid it being set
# by mock to a MagicMock class, which won't pass the checks for valid FILE.
fake_input_file = "./fake_input_file.tflite"
Path(fake_input_file).touch()
cli_args.FILE = fake_input_file

tvmc.autotuner.drive_tune(cli_args)

os.remove(fake_input_file)

mock_tune_model.assert_called_once()

# inspect the mock call, to search for specific arguments
Expand Down

0 comments on commit 2d2951a

Please sign in to comment.