Update test suite to modern pytest

- Use pytest>=6.2 features (same as install_requires).
  When we can require >=7, can fix some more typing omissions and
  version checks.
- Replace testdir with pytester
- Replace py.test with pytest
- Replace tmpdir with tmp_path
- Remove (almost) all other uses of py
- Add some type annotations (not checked yet)

Ref #722.
This commit is contained in:
Ran Benita
2021-10-30 11:02:23 +03:00
parent 5672d85809
commit 9ddb274f23
11 changed files with 768 additions and 689 deletions

View File

@@ -1,12 +1,13 @@
import py
import pytest
import execnet
import pytest
import shutil
from typing import List
pytest_plugins = "pytester"
@pytest.fixture(autouse=True)
def _divert_atexit(request, monkeypatch):
def _divert_atexit(request, monkeypatch: pytest.MonkeyPatch):
import atexit
finalizers = []
@@ -23,7 +24,7 @@ def _divert_atexit(request, monkeypatch):
func(*args, **kwargs)
def pytest_addoption(parser):
def pytest_addoption(parser) -> None:
parser.addoption(
"--gx",
action="append",
@@ -33,28 +34,28 @@ def pytest_addoption(parser):
@pytest.fixture
def specssh(request):
def specssh(request) -> str:
return getspecssh(request.config)
# configuration information for tests
def getgspecs(config):
def getgspecs(config) -> List[execnet.XSpec]:
return [execnet.XSpec(spec) for spec in config.getvalueorskip("gspecs")]
def getspecssh(config):
def getspecssh(config) -> str: # type: ignore[return]
xspecs = getgspecs(config)
for spec in xspecs:
if spec.ssh:
if not py.path.local.sysfind("ssh"):
py.test.skip("command not found: ssh")
if not shutil.which("ssh"):
pytest.skip("command not found: ssh")
return str(spec)
py.test.skip("need '--gx ssh=...'")
pytest.skip("need '--gx ssh=...'")
def getsocketspec(config):
def getsocketspec(config) -> execnet.XSpec:
xspecs = getgspecs(config)
for spec in xspecs:
if spec.socket:
return spec
py.test.skip("need '--gx socket=...'")
pytest.skip("need '--gx socket=...'")