Skip to content

Commit 2f55a0d

Browse files
Add a --no-functional CLI flag for running tests. (microsoft#4768)
(for microsoft#4739) This will facilitate optionally skipping functional tests (under pythonFiles) for the sake of speed. Functional tests (or suites) will be marked with the "functional" marker: ```python @pytest.mark.functional def test_spam(): ... @pytest.mark.functional class TestSpam: def test_x(self): ... ```
1 parent 4e7df1e commit 2f55a0d

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

pythonFiles/tests/__main__.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
import argparse
45
import os.path
56
import sys
67

@@ -13,16 +14,35 @@
1314
TESTING_TOOLS_ROOT = os.path.join(SRC_ROOT, 'testing_tools')
1415

1516

16-
def main(argv=sys.argv[1:]):
17+
def parse_args():
18+
parser = argparse.ArgumentParser()
19+
# To mark a test as functional: (decorator) @pytest.mark.functional
20+
parser.add_argument('--no-functional', dest='markers',
21+
action='append_const', const='not functional')
22+
args, remainder = parser.parse_known_args()
23+
24+
ns = vars(args)
25+
26+
return ns, remainder
27+
28+
29+
def main(pytestargs, markers=None):
1730
sys.path.insert(1, DATASCIENCE_ROOT)
1831
sys.path.insert(1, TESTING_TOOLS_ROOT)
19-
ec = pytest.main([
32+
33+
pytestargs = [
2034
'--rootdir', SRC_ROOT,
2135
TEST_ROOT,
22-
] + argv)
36+
] + pytestargs
37+
for marker in reversed(markers or ()):
38+
pytestargs.insert(0, marker)
39+
pytestargs.insert(0, '-m')
40+
41+
ec = pytest.main(pytestargs)
2342
return ec
2443

2544

2645
if __name__ == '__main__':
27-
ec = main()
46+
mainkwargs, pytestargs = parse_args()
47+
ec = main(pytestargs, **mainkwargs)
2848
sys.exit(ec)

pythonFiles/tests/run_all.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
os.path.dirname(
99
os.path.abspath(__file__)))
1010

11-
from tests.__main__ import main
11+
from tests.__main__ import main, parse_args
1212

1313

1414
if __name__ == '__main__':
15-
ec = main()
15+
mainkwargs, pytestargs = parse_args()
16+
ec = main(pytestargs, **mainkwargs)
1617
sys.exit(ec)

0 commit comments

Comments
 (0)