Skip to content

Commit

Permalink
Add mechanism for CI to force unskip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mreso committed Dec 8, 2023
1 parent 0022d97 commit a71a68b
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit a71a68b

Please sign in to comment.