Skip to content

Commit 42f6368

Browse files
committed
ci: oneshot-test: create an artifact out of failed tests
Create an artifact out of failed tests, which allows us to inspect them (the frozen application itself and the build directory with .toc files and xref.html for debugging import chains).
1 parent 60b65eb commit 42f6368

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/oneshot-test.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ jobs:
139139

140140
# Finally, the usual: setup Python, install dependencies, test.
141141
steps:
142-
- uses: actions/checkout@v6
142+
- name: Checkout pyinstaller-hooks-contrib code
143+
uses: actions/checkout@v6
143144

144145
- name: Set up Python ${{ matrix.python-version }}
145146
uses: actions/setup-python@v6
@@ -169,5 +170,55 @@ jobs:
169170
# Install PyInstaller
170171
pip install ${{ github.event.inputs.pyinstaller }}
171172
173+
# Relocate the temporary directory to a fixed location so we can
174+
# generate artifacts out of failed tests.
175+
- name: Relocate temporary dir
176+
shell: bash
177+
run: |
178+
echo "PYTEST_DEBUG_TEMPROOT=$RUNNER_TEMP" >> $GITHUB_ENV
179+
172180
- name: Run tests
181+
id: run-tests
173182
run: pytest -v -n logical ${{ inputs.pytest_args }}
183+
184+
# On all platforms, create a tarball to ensure that symlinks are preserved.
185+
# Avoid using compression here, as the tarball will end up collected into
186+
# artifact zip archive. To simplify this across platforms, run this step
187+
# in python and use python's tarfile module.
188+
- name: Archive failed tests
189+
if: ${{ failure() && steps.run-tests.outcome == 'failure' }}
190+
shell: python
191+
run: |
192+
import os
193+
import sys
194+
import tarfile
195+
196+
try:
197+
import getpass
198+
user = getpass.getuser() or "unknown"
199+
except Exception:
200+
user = "unknown"
201+
202+
temproot = os.environ['PYTEST_DEBUG_TEMPROOT']
203+
204+
pytest_name = f'pytest-of-{user}'
205+
pytest_fullpath = os.path.join(temproot, pytest_name)
206+
print(f"Input directory: {pytest_fullpath}!", file=sys.stderr)
207+
208+
output_file = os.path.join(temproot, 'archived-failed-tests.tar')
209+
print(f"Output file: {output_file}!", file=sys.stderr)
210+
211+
assert os.path.isdir(pytest_fullpath)
212+
assert not os.path.exists(output_file)
213+
214+
with tarfile.open(output_file, "w") as tf:
215+
tf.add(pytest_fullpath, arcname=pytest_name, recursive=True)
216+
217+
print(f"Created {output_file}!", file=sys.stderr)
218+
219+
- name: Create artifact out of archived failed tests
220+
if: ${{ failure() && steps.run-tests.outcome == 'failure' }}
221+
uses: actions/upload-artifact@v6
222+
with:
223+
name: failed-tests-${{ matrix.os }}-python-${{ matrix.python-version }}
224+
path: '${{ env.PYTEST_DEBUG_TEMPROOT }}/archived-failed-tests.tar'

0 commit comments

Comments
 (0)