From a71a68b8cc77343a75a93f6388fd65170a8ffdb2 Mon Sep 17 00:00:00 2001 From: Matthias Reso <13337103+mreso@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:42:21 -0800 Subject: [PATCH] Add mechanism for CI to force unskip tests --- tests/conftest.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 652edbe28..7cbef6d7b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,12 +5,18 @@ from transformers import LlamaTokenizer +ACCESS_ERROR_MSG = "Could not access tokenizer at 'meta-llama/Llama-2-7b-hf'. Did you log into huggingface hub and provided the correct token?" + +unskip_missing_tokenizer = False + @pytest.fixture(scope="module") def llama_tokenizer(): try: return LlamaTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf") - except OSError: - return None + except OSError as e: + if unskip_missing_tokenizer: + raise e + return None @pytest.fixture @@ -21,8 +27,24 @@ def _helper(tokenizer_mock): return _helper + @pytest.fixture(autouse=True) def skip_if_tokenizer_is_missing(request, llama_tokenizer): - if request.node.get_closest_marker("skip_missing_tokenizer"): + if request.node.get_closest_marker("skip_missing_tokenizer") and not unskip_missing_tokenizer: if llama_tokenizer is None: - pytest.skip("Llama tokenizer could not be accessed. Did you log into huggingface hub and provided the correct token?") + pytest.skip(ACCESS_ERROR_MSG) + + +def pytest_addoption(parser): + parser.addoption( + "--unskip-missing-tokenizer", + action="store_true", + default=False, help="disable skip missing tokenizer") + + +@pytest.hookimpl(tryfirst=True) +def pytest_cmdline_preparse(config, args): + if "--unskip-missing-tokenizer" not in args: + return + global unskip_missing_tokenizer + unskip_missing_tokenizer = True