test_ok2/testing/test_modimport.py

41 lines
949 B
Python
Raw Normal View History

2017-03-16 01:11:19 +08:00
import subprocess
import sys
import py
2017-03-16 01:11:19 +08:00
import _pytest
import pytest
2017-03-16 01:11:19 +08:00
pytestmark = pytest.mark.slow
2017-03-16 01:11:19 +08:00
MODSET = [
2018-05-23 22:48:46 +08:00
x
for x in py.path.local(_pytest.__file__).dirpath().visit("*.py")
if x.purebasename != "__init__"
2017-03-16 01:11:19 +08:00
]
2018-05-23 22:48:46 +08:00
@pytest.mark.parametrize("modfile", MODSET, ids=lambda x: x.purebasename)
2017-03-16 01:11:19 +08:00
def test_fileimport(modfile):
# this test ensures all internal packages can import
# without needing the pytest namespace being set
# this is critical for the initialization of xdist
p = subprocess.Popen(
2018-05-23 22:48:46 +08:00
[
sys.executable,
"-c",
"import sys, py; py.path.local(sys.argv[1]).pyimport()",
modfile.strpath,
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
2018-05-23 22:48:46 +08:00
)
(out, err) = p.communicate()
2019-03-23 00:16:08 +08:00
assert p.returncode == 0, "importing %s failed (exitcode %d): out=%r, err=%r" % (
modfile,
p.returncode,
out,
err,
)