Download tests/conftest.py from Necthrall/AI: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/Necthrall/AI/resolve/main/tests/conftest.py
- Command line
-
hf download hf://spaces/Necthrall/AI/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/spaces/Necthrall/AI/resolve/main/tests/conftest.py
1.37 kB
| """Pytest conftest for Necthrall test configuration. | |
| This file sets up the test environment with proper threading settings | |
| and handles Windows-specific configurations. | |
| """ | |
| import os | |
| import sys | |
| # Set environment variables BEFORE any imports that might use parallel processing | |
| os.environ.setdefault("TOKENIZERS_PARALLELISM", "false") | |
| # WINDOWS DLL FIX: Add torch/lib to DLL search path if torch is installed | |
| # This MUST happen before importing torch or any library that uses torch | |
| if os.name == "nt": | |
| try: | |
| torch_lib = os.path.join(sys.prefix, "Lib", "site-packages", "torch", "lib") | |
| if os.path.isdir(torch_lib): | |
| try: | |
| os.add_dll_directory(torch_lib) | |
| except Exception: | |
| os.environ["PATH"] = torch_lib + os.pathsep + os.environ.get("PATH", "") | |
| except Exception: | |
| pass | |
| # CRITICAL: Import torch FIRST before any other library that might load conflicting DLLs | |
| # This prevents DLL conflicts with onnxruntime, sentence-transformers, etc. | |
| # Wrapped in try/except to continue if this fails - tests may still work with mocking | |
| try: | |
| import torch # noqa: F401 | |
| _torch_loaded = True | |
| except (ImportError, OSError): | |
| _torch_loaded = False | |
| # Import fitz (PyMuPDF) early if available - it has its own DLL requirements | |
| try: | |
| import fitz # noqa: F401 | |
| except ImportError: | |
| pass | |