File size: 986 Bytes
06c11b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537c169
 
 
06c11b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations

import importlib
import sys
from pathlib import Path

import pytest


def _find_repo_root(start_file: str | Path) -> Path:
    path = Path(start_file).resolve()
    cur = path if path.is_dir() else path.parent
    for candidate in (cur, *cur.parents):
        if (candidate / "pyproject.toml").exists():
            return candidate
    raise FileNotFoundError(f"Could not find repo root from {path}")


REPO_ROOT = _find_repo_root(__file__)
SRC_ROOT = REPO_ROOT / "src"
GRADIO_ROOT = REPO_ROOT / "gradio-web"
if not GRADIO_ROOT.exists():
    GRADIO_ROOT = REPO_ROOT / "gradio"

for p in (str(REPO_ROOT), str(SRC_ROOT), str(GRADIO_ROOT)):
    if p not in sys.path:
        sys.path.insert(0, p)


@pytest.fixture(scope="session")
def repo_root() -> Path:
    return REPO_ROOT


@pytest.fixture
def reload_module():
    def _reload(name: str):
        module = importlib.import_module(name)
        return importlib.reload(module)

    return _reload