Skip to content

Commit ec93778

Browse files
committed
Fix flaky tests, by preheating Pyright
1 parent 0b50914 commit ec93778

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

.github/workflows/test.yaml

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Unit Test
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ main, test ]
66
pull_request:
77

88
jobs:
@@ -17,12 +17,14 @@ jobs:
1717
cache: true
1818
- name: Install dependencies
1919
run: pdm install
20-
- name: Run tests with retry
21-
uses: nick-fields/retry@v2
22-
with:
23-
timeout_minutes: 10
24-
max_attempts: 3
25-
command: pdm run test
20+
- name: Preheat Pyright
21+
# If we don't do this, each pytest-xdist process will try to install the
22+
# dependencies of Pyright (Node.js packages, pyi). Each installation assumes
23+
# it's a clean install, and will error if files already exist.
24+
run: pdm run pyright --pythonversion 3.12 challenges/basic-any/solution.py
25+
continue-on-error: true
26+
- name: Run tests
27+
run: pdm run test
2628
- name: Send failure email
2729
if: failure()
2830
uses: dawidd6/action-send-mail@v3

views/challenge.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,16 @@ def _type_check_with_pyright(
151151
["pyright", "--pythonversion", "3.12", temp.name],
152152
capture_output=True,
153153
text=True,
154-
).stdout
154+
)
155+
stdout, stderr = raw_result.stdout, raw_result.stderr
156+
if stderr:
157+
return TypeCheckResult(message=stderr, passed=False)
155158
error_lines: list[str] = []
156159

157160
# Substract lineno in merged code by lineno_delta, so that the lineno in
158161
# error message matches those in the test code editor. Fixed #20.
159162
lineno_delta = len(user_code.splitlines())
160-
for line in raw_result.splitlines():
163+
for line in stdout.splitlines():
161164
m = re.match(cls.PYRIGHT_MESSAGE_REGEX, line)
162165
if m is None:
163166
continue

0 commit comments

Comments
 (0)