Safely import pytest in testing_utils.py (#24241)
This commit is contained in:
@@ -36,18 +36,6 @@ from unittest import mock
|
||||
|
||||
import huggingface_hub
|
||||
import requests
|
||||
from _pytest.doctest import (
|
||||
Module,
|
||||
_get_checker,
|
||||
_get_continue_on_failure,
|
||||
_get_runner,
|
||||
_is_mocked,
|
||||
_patch_unwrap_mock_aware,
|
||||
get_optionflags,
|
||||
import_path,
|
||||
)
|
||||
from _pytest.outcomes import skip
|
||||
from pytest import DoctestItem
|
||||
|
||||
from transformers import logging as transformers_logging
|
||||
|
||||
@@ -83,6 +71,7 @@ from .utils import (
|
||||
is_phonemizer_available,
|
||||
is_pyctcdecode_available,
|
||||
is_pytesseract_available,
|
||||
is_pytest_available,
|
||||
is_pytorch_quantization_available,
|
||||
is_rjieba_available,
|
||||
is_safetensors_available,
|
||||
@@ -116,6 +105,24 @@ if is_accelerate_available():
|
||||
from accelerate.state import AcceleratorState, PartialState
|
||||
|
||||
|
||||
if is_pytest_available():
|
||||
from _pytest.doctest import (
|
||||
Module,
|
||||
_get_checker,
|
||||
_get_continue_on_failure,
|
||||
_get_runner,
|
||||
_is_mocked,
|
||||
_patch_unwrap_mock_aware,
|
||||
get_optionflags,
|
||||
import_path,
|
||||
)
|
||||
from _pytest.outcomes import skip
|
||||
from pytest import DoctestItem
|
||||
else:
|
||||
Module = object
|
||||
DoctestItem = object
|
||||
|
||||
|
||||
SMALL_MODEL_IDENTIFIER = "julien-c/bert-xsmall-dummy"
|
||||
DUMMY_UNKNOWN_IDENTIFIER = "julien-c/dummy-unknown"
|
||||
DUMMY_DIFF_TOKENIZER_IDENTIFIER = "julien-c/dummy-diff-tokenizer"
|
||||
|
||||
@@ -133,6 +133,7 @@ from .import_utils import (
|
||||
is_py3nvml_available,
|
||||
is_pyctcdecode_available,
|
||||
is_pytesseract_available,
|
||||
is_pytest_available,
|
||||
is_pytorch_quantization_available,
|
||||
is_rjieba_available,
|
||||
is_sacremoses_available,
|
||||
|
||||
@@ -105,6 +105,7 @@ _psutil_available = _is_package_available("psutil")
|
||||
_py3nvml_available = _is_package_available("py3nvml")
|
||||
_pyctcdecode_available = _is_package_available("pyctcdecode")
|
||||
_pytesseract_available = _is_package_available("pytesseract")
|
||||
_pytest_available = _is_package_available("pytest")
|
||||
_pytorch_quantization_available = _is_package_available("pytorch_quantization")
|
||||
_rjieba_available = _is_package_available("rjieba")
|
||||
_sacremoses_available = _is_package_available("sacremoses")
|
||||
@@ -547,6 +548,10 @@ def is_pytesseract_available():
|
||||
return _pytesseract_available
|
||||
|
||||
|
||||
def is_pytest_available():
|
||||
return _pytest_available
|
||||
|
||||
|
||||
def is_spacy_available():
|
||||
return _spacy_available
|
||||
|
||||
|
||||
Reference in New Issue
Block a user