Skip to content

Commit d183045

Browse files
committed
Add a check for tests which are always skipped
This takes the form of a new script which crawls pytest XML reports and collates them into a single aggregate. It checks for tests which are skipped or missing in all of the reports. The aggregator can be run along with a suite of tox environments via `make collatd-test-report`, and a new CI job runs this in a build.
1 parent 5c71afa commit d183045

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

.github/workflows/build.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ jobs:
7878
python -m tox run-parallel -m ci
7979
python -m tox run -e cov
8080
81+
collate-tests:
82+
runs-on: ubuntu-latest
83+
name: "Collate results to check for skipped tests"
84+
steps:
85+
- uses: actions/checkout@v3
86+
87+
- name: get date for caching
88+
run: /bin/date -u "+%U" > cachedate.txt
89+
shell: bash
90+
91+
- uses: actions/setup-python@v4
92+
with:
93+
python-version: |
94+
3.7
95+
3.10
96+
3.11
97+
cache: "pip"
98+
cache-dependency-path: |
99+
.github/workflows/build.yaml
100+
setup.cfg
101+
tox.ini
102+
cachedate.txt
103+
104+
- run: python -m pip install tox
105+
106+
- run: make collated-test-report
107+
81108
self-check:
82109
name: "Self-Check"
83110
runs-on: ubuntu-latest

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ release:
1717
-git push $(shell git rev-parse --abbrev-ref @{push} | cut -d '/' -f1) refs/tags/$(PKG_VERSION)
1818
tox run -e publish-release
1919

20+
.PHONY: collated-test-report
21+
collated-test-report:
22+
tox p -e py37-mindeps,py311,py310-notoml,py310-tomli-format,py311-json5 -- '--junitxml={envdir}/pytest.xml'
23+
python ./scripts/aggregate-pytest-reports.py \
24+
.tox/py37-mindeps/pytest.xml \
25+
.tox/py311/pytest.xml \
26+
.tox/py310-notoml/pytest.xml \
27+
.tox/py310-tomli-format/pytest.xml \
28+
.tox/py311-json5/pytest.xml
29+
2030
.PHONY: clean
2131
clean:
2232
rm -rf dist build *.egg-info .tox .coverage.*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import argparse
2+
import sys
3+
from collections import defaultdict
4+
from xml.etree import ElementTree # nosec
5+
6+
7+
def main():
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument("FILES", nargs="+")
10+
args = parser.parse_args()
11+
12+
tests_by_name = defaultdict(dict)
13+
for filename in args.FILES:
14+
tree = ElementTree.parse(filename)
15+
root = tree.getroot()
16+
17+
for testcase in root.findall("./testsuite/testcase"):
18+
classname = testcase.get("classname")
19+
name = testcase.get("name")
20+
nodename = f"{classname.replace('.', '/')}.py::{name}"
21+
22+
skip_node = testcase.find("skipped")
23+
if skip_node is not None:
24+
if "skipped" not in tests_by_name[nodename]:
25+
tests_by_name[nodename]["skipped"] = True
26+
else:
27+
tests_by_name[nodename]["skipped"] = False
28+
29+
fail = False
30+
for nodename, attributes in tests_by_name.items():
31+
if attributes.get("skipped") is True:
32+
print(f"ALWAYS SKIPPED: {nodename}")
33+
fail = True
34+
35+
if fail:
36+
print("fail")
37+
sys.exit(1)
38+
print("ok")
39+
sys.exit(0)
40+
41+
42+
if __name__ == "__main__":
43+
main()

0 commit comments

Comments
 (0)