File size: 1,576 Bytes
22e0325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
# SPDX-License-Identifier: Apache-2.0
"""pytest settings of PaddleOCR-VL (no dependency on tt-metal's own conftest).

- Host tests (``tests/test_host_*.py``) never open a device (the fake backend):
  ``TT_VISIBLE_DEVICES=none python -m pytest code/tt_paddleocr/tests/test_host_api.py
  code/tt_paddleocr/tests/test_host_server.py code/tt_paddleocr/tests/test_host_core.py``; tests that need checkpoint
  files read ``PADDLEOCR_TEST_WEIGHTS`` or the pinned snapshot in the Hugging Face cache, and skip otherwise.
- The device gates and benchmarks of the port are development scripts kept outside the package; the shipped latency
  benchmark is ``code/scripts/bench.py``.
- Tests marked ``device`` are skipped when ttnn is missing or ``TT_VISIBLE_DEVICES=none``.
"""
from __future__ import annotations

import gc
import importlib.util
import os

import pytest


def pytest_configure(config):
    config.addinivalue_line("markers", "device: needs a Tenstorrent chip (skipped on host-only runs)")


def _no_device_reason():
    if os.environ.get("TT_VISIBLE_DEVICES", "").lower() == "none":
        return "TT_VISIBLE_DEVICES=none (host-only run)"
    if importlib.util.find_spec("ttnn") is None:
        return "ttnn is not installed"
    return None


def pytest_collection_modifyitems(config, items):
    reason = _no_device_reason()
    if reason:
        skip = pytest.mark.skip(reason=reason)
        for item in items:
            if "device" in item.keywords:
                item.add_marker(skip)


@pytest.fixture(autouse=True)
def _gc_between_tests():
    gc.collect()