Optional Practice: Automate a Test
Use GitHub Actions to show a collaborator that your committed code passes its tests. Then introduce a bug and check that the same test fails locally and on GitHub before repairing it. This optional exercise has no points or Gradescope submission.
Start
Create a separate ci-practice repository containing only your completed lab.py from the Python lab. Publish it under your GitHub account using the first lab’s steps; leave environments and credentials out.
From the ci-practice terminal, run the existing doctests:
$ python -m doctest -v lab.pyThe report should end with Test passed.; fix failures before automating it.
Run the Same Test on GitHub
In VS Code, create .github/workflows/doctests.yml with this content:
name: Doctests
on:
workflow_dispatch:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.12'
- name: Run doctests
run: python -m doctest -v lab.pyThe runner checks out your committed files, installs Python 3.12, and runs the same doctest command. workflow_dispatch means you start each run manually.
Commit and sync both files to the repository’s default branch, usually main. Open the repository on GitHub, select Actions → Doctests → Run workflow, choose that branch, and start the run. Open the completed run, then test → Run doctests, to read the report. Its passing examples should match your local report.
If the workflow is missing, confirm that .github/workflows/doctests.yml appears on GitHub’s default branch and refresh the Actions page. If Actions is disabled for this practice repository, enable it under Settings → Actions → General. If account policy or a usage limit blocks the run, keep practicing locally; this exercise is optional. GitHub’s manual-run instructions describe the same controls.
Break It and Fix It
In this practice copy of lab.py, change the body of is_even to return False, leaving its doctests intact. Run the local command again and find a case that expected True but got False. Commit and sync the broken version, then manually run the workflow again. The Run doctests step should fail with the same example.
Restore your working implementation, rerun the local command, commit and sync, and request one final workflow run. Both reports should pass again.
Submit
Keep the corrected code on the default branch and a failed run followed by a successful one in the Actions history. The workflow remains manual, so future pushes do not start extra runs.