Skip to content

Commit 1331d7c

Browse files
author
Jonas Danke
committed
update
1 parent 4d3cb68 commit 1331d7c

5 files changed

Lines changed: 136 additions & 20 deletions

File tree

.github/workflows/tests.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,33 @@ jobs:
4141
--junitxml=fast-report.xml
4242
4343

44-
- name: Run edisgo
44+
45+
- name: Run fast tests from file
4546
run: |
46-
python -m pytest tests/test_edisgo.py -vv \
47-
-k "not oedb and not import_heat_pumps" \
48-
--runslow \
49-
--runonlinux \
50-
--html=edisgo-report.html \
51-
--self-contained-html \
52-
--junitxml=edisgo-report.xml
47+
python tests/run_tests_from_file.py
5348
54-
55-
- name: Upload fast test reports
49+
- name: Upload fast reports
5650
if: always()
5751
uses: actions/upload-artifact@v4
5852
with:
5953
name: fast-test-reports
6054
path: |
61-
fast-report.xml
6255
fast-report.html
56+
fast-report.xml
57+
6358
64-
- name: Upload edisgo report
59+
- name: Upload fast test reports
6560
if: always()
6661
uses: actions/upload-artifact@v4
6762
with:
68-
name: edisgo-test-report
63+
name: fast-test-reports
6964
path: |
70-
edisgo-report.html
71-
edisgo-report.xml
65+
fast-report.xml
66+
fast-report.html
67+
68+
# - name: Run non-fast tests
69+
# run: |
70+
# python tests/run_tests_from_file.py ci/non_fast_tests.txt
7271

7372
full-tests:
7473
if: github.event_name == 'pull_request'

tests/collect_fast_tests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import subprocess
2+
from pathlib import Path
3+
4+
output_file = Path("ci/fast_tests.txt")
5+
output_file.parent.mkdir(exist_ok=True)
6+
7+
result = subprocess.run(
8+
[
9+
"python",
10+
"-m",
11+
"pytest",
12+
"--collect-only",
13+
"-q",
14+
"-m",
15+
"fast",
16+
],
17+
capture_output=True,
18+
text=True,
19+
check=False,
20+
)
21+
22+
tests = []
23+
24+
for line in result.stdout.splitlines():
25+
line = line.strip()
26+
27+
if not line:
28+
continue
29+
30+
if line.startswith("tests/") and "::" in line:
31+
tests.append(line)
32+
33+
with output_file.open("w", encoding="utf-8") as f:
34+
f.write("# Fast tests generated automatically\n")
35+
f.write("# Lines starting with # are ignored\n\n")
36+
37+
for test in tests:
38+
f.write(test + "\n")
39+
40+
print(f"Saved {len(tests)} fast tests to {output_file}")

tests/remove_fast_tests.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from pathlib import Path
2+
3+
all_tests_file = Path("all_tests.txt")
4+
fast_tests_file = Path("ci/fast_tests.txt")
5+
output_file = Path("ci/non_fast_tests.txt")
6+
7+
def load_tests(file_path):
8+
if not file_path.exists():
9+
return set()
10+
11+
tests = set()
12+
for line in file_path.read_text(encoding="utf-8").splitlines():
13+
line = line.strip()
14+
15+
if not line or line.startswith("#"):
16+
continue
17+
18+
tests.add(line)
19+
20+
return tests
21+
22+
all_tests = load_tests(all_tests_file)
23+
fast_tests = load_tests(fast_tests_file)
24+
25+
# quitar fast de todos
26+
non_fast_tests = sorted(all_tests - fast_tests)
27+
28+
output_file.parent.mkdir(exist_ok=True)
29+
30+
with output_file.open("w", encoding="utf-8") as f:
31+
f.write("# Non-fast tests (auto-generated)\n\n")
32+
for test in non_fast_tests:
33+
f.write(test + "\n")
34+
35+
print(f"Total tests: {len(all_tests)}")
36+
print(f"Fast tests: {len(fast_tests)}")
37+
print(f"Non-fast tests: {len(non_fast_tests)}")
38+
print(f"Saved to: {output_file}")

tests/run_tests_from_file.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import subprocess
2+
from pathlib import Path
3+
import sys
4+
5+
test_file = Path("ci/fast_tests.txt")
6+
7+
if not test_file.exists():
8+
print(f"ERROR: {test_file} does not exist")
9+
sys.exit(1)
10+
11+
tests = []
12+
13+
for line in test_file.read_text(encoding="utf-8").splitlines():
14+
line = line.strip()
15+
16+
if not line:
17+
continue
18+
19+
if line.startswith("#"):
20+
continue
21+
22+
tests.append(line)
23+
24+
if not tests:
25+
print("No active tests found in ci/fast_tests.txt")
26+
sys.exit(1)
27+
28+
cmd = [
29+
"python",
30+
"-m",
31+
"pytest",
32+
*tests,
33+
"-vv",
34+
"--html=fast-report.html",
35+
"--self-contained-html",
36+
"--junitxml=fast-report.xml",
37+
]
38+
39+
print("Running tests:")
40+
for test in tests:
41+
print(f" - {test}")
42+
43+
result = subprocess.run(cmd)
44+
sys.exit(result.returncode)

tests/test_sample.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)