Skip to content

Commit 4918eca

Browse files
authored
Merge pull request #1181 from jameshcorbett/python-test-under-flux
test: run t10001 under flux
2 parents 8895bea + 3c3c8d4 commit 4918eca

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

t/python/subflux.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Utility for re-running python tests under flux.
3+
4+
Copied from flux-core.
5+
"""
6+
7+
###############################################################
8+
# Copyright 2014 Lawrence Livermore National Security, LLC
9+
# (c.f. AUTHORS, NOTICE.LLNS, COPYING)
10+
#
11+
# This file is part of the Flux resource manager framework.
12+
# For details, see https://github.com/flux-framework.
13+
#
14+
# SPDX-License-Identifier: LGPL-3.0
15+
###############################################################
16+
17+
import argparse
18+
import os
19+
import subprocess
20+
import sys
21+
import shutil
22+
23+
24+
# Ignore -v, --verbose and --root options so that python test scripts
25+
# can absorb the same options as sharness tests. Later, something could
26+
# be done with these options, but for now they are dropped silently.
27+
parser = argparse.ArgumentParser()
28+
parser.add_argument("--debug", "-d", action="store_true")
29+
parser.add_argument("--root", metavar="PATH", type=str)
30+
args, remainder = parser.parse_known_args()
31+
32+
sys.argv[1:] = remainder
33+
34+
35+
def rerun_under_flux(size=1):
36+
try:
37+
if os.environ["IN_SUBFLUX"] == "1":
38+
return True
39+
except KeyError:
40+
pass
41+
42+
child_env = dict(**os.environ)
43+
child_env["IN_SUBFLUX"] = "1"
44+
45+
# ported from sharness.d/flux-sharness.sh
46+
command = [shutil.which("flux"), "start", "--test-size", str(size)]
47+
48+
command.extend([sys.executable, sys.argv[0]])
49+
50+
p = subprocess.Popen(
51+
command, env=child_env, bufsize=-1, stdout=sys.stdout, stderr=sys.stderr
52+
)
53+
p.wait()
54+
if p.returncode > 0:
55+
sys.exit(p.returncode)
56+
elif p.returncode < 0:
57+
sys.exit(128 + -p.returncode)
58+
return False

t/python/t10001-resourcegraph.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,8 @@ def test_basic_3(self):
111111
self.assertEqual(metadata["properties"]["pbatch"], "")
112112

113113

114-
unittest.main(testRunner=TAPTestRunner())
114+
if __name__ == "__main__":
115+
from subflux import rerun_under_flux
116+
117+
if rerun_under_flux(size=1):
118+
unittest.main(testRunner=TAPTestRunner())

0 commit comments

Comments
 (0)