Found by Codex global repository scan of deepmodeling/dpgen2 at commit 2679611a3704f5c2646c8cb353e34177518db758.
The helper under tests/fp/data.vasp.kp.gf is named make_kp_test.py, which matches pytest's default *_test.py collection pattern. It also runs generation code at import time:
|
#!/usr/bin/env python3 |
|
|
|
import os |
|
|
|
import ase |
|
import dpdata |
|
import numpy as np |
|
|
|
|
|
def make_one(out_dir): |
|
# [0.5, 1) |
|
[aa, bb, cc] = np.random.random(3) * 0.5 + 0.5 |
|
# [1, 179) |
|
[alpha, beta, gamma] = np.random.random(3) * (178 / 180) + 1 |
|
# make cell |
|
cell = ase.geometry.cellpar_to_cell([aa, bb, cc, alpha, beta, gamma]) |
|
sys = dpdata.System("POSCAR") |
|
sys["cells"][0] = cell |
|
os.makedirs(out_dir, exist_ok=True) |
|
sys.to_vasp_poscar(os.path.join(out_dir, "POSCAR")) |
|
|
|
|
|
ntest = 30 |
|
for ii in range(ntest): |
|
out_dir = "test.%03d" % ii |
|
make_one(out_dir) |
During a plain pytest -q collection in the scanned checkout, pytest imported this helper and executed the top-level loop before real tests ran. In this environment it failed with:
AttributeError: module 'ase' has no attribute 'geometry'
Even when the import succeeds, collecting a data-generation helper can mutate test data during discovery.
Suggested fix: rename the helper so pytest does not collect it, add if __name__ == "__main__" around the generation loop, or add explicit collection ignores for data helper scripts.
Found by Codex global repository scan of
deepmodeling/dpgen2at commit2679611a3704f5c2646c8cb353e34177518db758.The helper under
tests/fp/data.vasp.kp.gfis namedmake_kp_test.py, which matches pytest's default*_test.pycollection pattern. It also runs generation code at import time:dpgen2/tests/fp/data.vasp.kp.gf/make_kp_test.py
Lines 1 to 26 in 2679611
During a plain
pytest -qcollection in the scanned checkout, pytest imported this helper and executed the top-level loop before real tests ran. In this environment it failed with:Even when the import succeeds, collecting a data-generation helper can mutate test data during discovery.
Suggested fix: rename the helper so pytest does not collect it, add
if __name__ == "__main__"around the generation loop, or add explicit collection ignores for data helper scripts.