summaryrefslogtreecommitdiffstats
path: root/debian/tests/unit-tests-stable.py
blob: f440449913def45f79fab3644a8626a1342fb511 (plain)
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
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python3

import glob
import os
import subprocess
import sys

sys.dont_write_bytecode = True
from flaky_tests_list import flaky_test_dirs

cwd = os.getcwd()

overall_test_rc = 0
failed_tests = []

# find all dirs that have unit tests
for i in glob.glob('ansible_collections/**/tests/unit', recursive=True):

    # base path to run ansible-test is two levels up
    testdir = os.path.normpath(
        os.path.join(i, '..', '..')
    )

    # skip any tests that are flagged as flaky
    if testdir in flaky_test_dirs:
        print("Skipping", testdir)
        continue

    os.chdir(testdir)

    print ("\n\n", flush=True)
    print ("############################################################", flush=True)
    print ("############################################################", flush=True)
    print ("#### Running tests in", testdir, flush=True)
    print ("############################################################", flush=True)
    print ("############################################################", flush=True)

    rc = subprocess.run([
        '/usr/bin/ansible-test',
        'units',
        '--python-interpreter',
        '/usr/bin/python3',
        '--local'
    ])


    if rc.returncode != 0:
        failed_tests.append(i)
        overall_test_rc = rc.returncode

    os.chdir(cwd)


if overall_test_rc != 0:
    print ("############################################################", flush=True)
    print ("############################################################", flush=True)
    print ("#### failed tests are:", flush=True)
    for i in failed_tests:
        print ("####", i, flush=True)
    print ("############################################################", flush=True)
    print ("############################################################", flush=True)

exit(overall_test_rc)