This repository is used in the Collaborative Programming lab to introduce several important software engineering practices used in real-world development:
- Git for version control
- GitHub for collaboration
- pytest for automated testing
- GitHub Actions for Continuous Integration (CI)
You will complete several Python exercises and submit your work using a Pull Request workflow.
learn-git-pytest
│
├── exercise1/
│ └── calculator.py
│
├── exercise2/
│ └── strings.py
│
├── exercise3/
│ └── temperature.py
│
├── tests/
│ ├── test_exercise1.py
│ ├── test_exercise2.py
│ └── test_exercise3.py
│
└── requirements.txt
Each exercise contains incomplete Python functions that you must implement.
The tests/ folder contains automated tests that verify your solutions.
By completing this lab you will learn:
- Forking a repository
- Cloning a repository
- Creating branches
- Committing changes
- Pushing code to GitHub
- Running tests with pytest
- Understanding test failures
- Fixing code until tests pass
- Running automated checks using GitHub Actions
- Understanding CI pipelines
- Verifying code quality automatically
You can write the section like this so it stays simple and consistent for students.
You must install the following tools.
If you are using Windows, you can install some tools directly from the terminal.
Open PowerShell and run:
winget install Git.GitVerify installation:
git --versionwinget search Python.Python.3.11Verify installation:
python --versionwinget install Microsoft.VisualStudioCodeAfter installation, open VS Code and install the Python extension.
Download and install from the official website:
https://github.com/apps/desktop
After installing, log in with your GitHub account.
GitHub Desktop provides a graphical interface for Git, which makes it easier to manage repositories, commits, and branches.
Go to the course repository on GitHub.
Click the Fork button in the top-right corner.
This creates your own copy of the repository under your GitHub account.
Clone your fork to your computer.
- Open GitHub Desktop
- Click File → Clone repository
- Select your fork
- Choose a location on your computer
Open the project folder using VS Code.
In the project folder, open a terminal and run:
python -m venv .venvThis creates an isolated Python environment.
.\.venv\Scripts\Activate.ps1Si il y a un problème
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser.venv\Scripts\activateYou should now see:
(.venv)
in your terminal prompt.
Install the required Python packages:
pip install -r requirements.txtThis installs:
- pytest
- mypy
- other required tools
Run the test suite:
pytest tests/You will notice that some tests fail.
Your task is to modify the code so that all tests pass.
Before modifying the code, create a branch with your name.
Example:
git checkout -b firstname-lastnameReplace firstname-lastname with your name.
Example:
git checkout -b alice-smith
Complete the missing functions in the exercise files.
Example files:
exercise1/calculator.py
exercise2/strings.py
exercise3/temperature.py
Run tests frequently:
pytest tests/When all tests pass, your implementation is correct.
Save your progress using Git.
git add .
git commit -m "Implement solutions for exercises"A commit records a snapshot of your work.
Upload your branch to your GitHub fork:
git push -u origin firstname-lastnameThis repository uses GitHub Actions to automatically verify your code.
Each time you push code:
- GitHub downloads your repository
- Installs Python
- Installs dependencies
- Runs type checking with mypy
- Runs all tests using pytest
You can see the results in the Actions tab of your GitHub repository.
If tests fail, you must fix your code and push again.
When all tests pass locally and in GitHub Actions:
- Go to the original course repository
- Click Pull Requests
- Click New Pull Request
- Click compare across forks
Then configure:
- Base repository: course repository
- Base branch:
main - Head repository: your fork
- Compare branch:
firstname-lastname
Add a title such as:
Exercise Solutions - Firstname Lastname
Click Create Pull Request.
Your instructor will:
- Review your code
- Verify that all tests pass
- Provide feedback in the Pull Request
- Approve or request changes
Fork repository
Clone repository
Create branch
Write code
Run tests locally
Commit changes
Push branch
Create Pull Request
Check GitHub Actions
Happy coding! 🚀