-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconftest.py
More file actions
53 lines (43 loc) · 1.65 KB
/
Copy pathconftest.py
File metadata and controls
53 lines (43 loc) · 1.65 KB
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
46
47
48
49
50
51
52
53
"""Repo-level pytest plugin, auto-discovered because the runner invokes
every `pytest --pyargs <module>` with cwd set to the repo root.
Two jobs:
1. PR-preview smoke runs: when the env var `PYTEST_LIMIT_N` is set to a
positive integer, pytest collects normally and then truncates the
test list to the first N items. This lets the PR matrix surface a
fast smoke signal per package (typically 10 tests each) without
per-package configuration.
2. Supply shared test fixtures that a package defines in its own
repo-root conftest.py but does not ship in the installed wheel.
`pytest --pyargs` collects from site-packages, so such fixtures are
otherwise missing and their tests error at setup. Currently:
`tmp_cwd` (astroquery).
"""
import os
from pathlib import Path
import pytest
def pytest_collection_modifyitems(config, items):
raw = os.environ.get("PYTEST_LIMIT_N")
if not raw:
return
try:
n = int(raw)
except ValueError:
return
if n > 0 and len(items) > n:
del items[n:]
@pytest.fixture(scope="function")
def tmp_cwd(tmp_path):
"""astroquery shim: run the test in a pristine temp working directory.
Exists solely for astroquery, which defines this fixture in its
repo-root conftest.py. That file is not part of the installed
package, so the fixture is missing under `pytest --pyargs
astroquery` and the esa/utils, esa/iso and esa/xmm_newton download
tests error out at setup. Remove this if astroquery ever ships the
fixture inside the package.
"""
old_dir = Path.cwd()
os.chdir(tmp_path)
try:
yield tmp_path
finally:
os.chdir(old_dir)