feat: update pytest-plugin for pytest-v8 (#4791)

This commit is contained in:
Noorhteen Raja NJ 2022-05-05 23:31:46 +05:30 committed by GitHub
parent 15ff663530
commit 3ecb463e0c
Failed to generate hash of commit

View file

@ -8,6 +8,7 @@ import os
import sys import sys
import types import types
import typing as tp import typing as tp
from pathlib import Path
from traceback import extract_tb, format_list from traceback import extract_tb, format_list
from unittest.mock import MagicMock from unittest.mock import MagicMock
@ -56,15 +57,15 @@ def _limited_traceback(excinfo):
return format_list(tb) return format_list(tb)
def pytest_collect_file(parent, path): def pytest_collect_file(file_path: Path, path, parent):
if path.ext.lower() == ".xsh" and path.basename.startswith("test_"): if file_path.suffix.lower() == ".xsh" and file_path.name.startswith("test_"):
return XshFile.from_parent(parent, fspath=path) return XshFile.from_parent(parent, path=file_path)
class XshFile(pytest.File): class XshFile(pytest.File):
def collect(self): def collect(self):
sys.path.append(self.fspath.dirname) sys.path.append(str(self.path.parent))
mod = importlib.import_module(self.fspath.purebasename) mod = importlib.import_module(self.path.stem)
sys.path.pop(0) sys.path.pop(0)
tests = [t for t in dir(mod) if t.startswith("test_")] tests = [t for t in dir(mod) if t.startswith("test_")]
for test_name in tests: for test_name in tests:
@ -92,7 +93,7 @@ class XshFunction(pytest.Item):
return "".join(formatted_tb) return "".join(formatted_tb)
def reportinfo(self): def reportinfo(self):
return self.fspath, 0, f"xonsh test: {self.name}" return self.path, 0, f"xonsh test: {self.name}"
@pytest.fixture @pytest.fixture