[tests] relocate core integration tests (#11146)
* relocate core integration tests * add sys.path context manager * cleanup * try * try2 * fix path * doc * style * add dep * add 2 more deps
This commit is contained in:
@@ -24,6 +24,7 @@ import unittest
|
||||
from distutils.util import strtobool
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from typing import Iterator, Union
|
||||
|
||||
from .file_utils import (
|
||||
is_datasets_available,
|
||||
@@ -621,6 +622,27 @@ class CaptureLogger:
|
||||
return f"captured: {self.out}\n"
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
# adapted from https://stackoverflow.com/a/64789046/9201239
|
||||
def ExtendSysPath(path: Union[str, os.PathLike]) -> Iterator[None]:
|
||||
"""
|
||||
Temporary add given path to `sys.path`.
|
||||
|
||||
Usage ::
|
||||
|
||||
with ExtendSysPath('/path/to/dir'):
|
||||
mymodule = importlib.import_module('mymodule')
|
||||
|
||||
"""
|
||||
|
||||
path = os.fspath(path)
|
||||
try:
|
||||
sys.path.insert(0, path)
|
||||
yield
|
||||
finally:
|
||||
sys.path.remove(path)
|
||||
|
||||
|
||||
class TestCasePlus(unittest.TestCase):
|
||||
"""
|
||||
This class extends `unittest.TestCase` with additional features.
|
||||
|
||||
Reference in New Issue
Block a user