Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is GitHub Actions used for in a Python project?
GitHub Actions automates tasks like running tests, building code, and deploying projects whenever you make changes. It helps check your Python code automatically using tools like PyTest.
Click to reveal answer
beginner
What is the purpose of the 'runs-on' key in a GitHub Actions workflow?
The 'runs-on' key tells GitHub which type of machine to use for running your workflow, like 'ubuntu-latest' for a Linux environment.
Click to reveal answer
beginner
Why do we use 'actions/checkout@v3' in a GitHub Actions workflow?
This action downloads your project code into the runner machine so the workflow can access and test your code.
Click to reveal answer
beginner
What command runs PyTest in a GitHub Actions workflow?
The command is 'pytest'. It runs all tests in your project and shows if they pass or fail.
Click to reveal answer
beginner
How do you specify Python version in GitHub Actions for testing?
Use the 'actions/setup-python@v4' action with the 'python-version' option to pick the Python version you want, like '3.12'.
Click to reveal answer
What does the 'actions/setup-python@v4' step do in a GitHub Actions workflow?
ASets up the Python environment with a specified version
BRuns PyTest tests
CChecks out the project code
DDeploys the application
✗ Incorrect
The 'actions/setup-python@v4' step installs the Python version you specify so your workflow can run Python commands.
Which command is used to run tests with PyTest in GitHub Actions?
Apython test.py
Bpytest
Crun tests
Dtest-run
✗ Incorrect
The 'pytest' command runs all tests found in your project automatically.
What is the purpose of the 'actions/checkout@v3' step?
ATo download your project code to the runner
BTo install dependencies
CTo run tests
DTo set environment variables
✗ Incorrect
This step downloads your project code so the workflow can access it.
In GitHub Actions, what does 'runs-on: ubuntu-latest' mean?
AUse the latest Windows machine
BUse a custom machine
CUse the latest Mac machine
DUse the latest Linux machine
✗ Incorrect
'ubuntu-latest' means the workflow runs on the latest Ubuntu Linux environment.
Why automate PyTest with GitHub Actions?
ATo manually run tests only when needed
BTo deploy code faster
CTo automatically check code quality on every change
DTo write tests automatically
✗ Incorrect
Automation helps catch errors early by running tests automatically on every code change.
Describe the basic steps to run PyTest tests automatically using GitHub Actions.
Think about how to prepare the environment and then run tests.
You got /4 concepts.
Explain why running tests automatically in GitHub Actions is helpful for a Python project.
Consider benefits of automation and continuous testing.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of running pytest in a GitHub Actions workflow?
easy
A. To automatically test code changes and catch errors early
B. To deploy the application to production
C. To create a backup of the repository
D. To format the code automatically
Solution
Step 1: Understand pytest's role in GitHub Actions CI
PyTest is a testing tool that checks if code works correctly. GitHub Actions runs tests automatically on code changes to catch errors early.
Final Answer:
To automatically test code changes and catch errors early -> Option A
Quick Check:
PyTest in GitHub Actions = automatic testing [OK]
Hint: PyTest in GitHub Actions runs tests automatically [OK]
Common Mistakes:
Confusing testing with deployment
Thinking PyTest formats code
Assuming it creates backups
2. Which of the following is the correct step to install PyTest in a GitHub Actions workflow YAML file?
easy
A. run: apt-get install pytest
B. run: npm install pytest
C. run: pip install pytest
D. run: brew install pytest
Solution
Step 1: Identify the package manager and correct install command for PyTest
PyTest is a Python package installed using pip. The correct command is run: pip install pytest.
Final Answer:
run: pip install pytest -> Option C
Quick Check:
Python packages use pip install [OK]
Hint: Use pip to install Python packages like PyTest [OK]
Common Mistakes:
Using npm which is for JavaScript
Using apt-get or brew which are system package managers
Missing the pip command
3. Given this GitHub Actions step in a workflow YAML file:
- name: Run tests
run: pytest tests/
What will happen when this step runs?
medium
A. PyTest will deploy the tests to a server
B. PyTest will install dependencies before running tests
C. PyTest will create a test report file automatically
D. PyTest will run all tests inside the tests/ directory
Solution
Step 1: Analyze the pytest tests/ command and default behavior
pytest tests/ runs all test files inside the tests/ folder by default but does not install dependencies or deploy code.
Final Answer:
PyTest will run all tests inside the tests/ directory -> Option D
Quick Check:
pytest tests/ runs tests in tests/ folder [OK]
Hint: pytest <folder> runs tests in that folder [OK]
Common Mistakes:
Thinking PyTest installs dependencies
Assuming PyTest deploys code
Expecting automatic report file creation
4. You wrote this GitHub Actions step:
- name: Run tests
run: py.test
But the workflow fails with "command not found" error. What is the likely cause?
medium
A. The command should be pytest not py.test
B. PyTest is not installed before running the tests
C. The tests directory is missing
D. GitHub Actions does not support running tests
Solution
Step 1: Diagnose the command not found error for py.test
PyTest must be installed first; both pytest and py.test work if installed.
Final Answer:
PyTest is not installed before running the tests -> Option B
Quick Check:
Install PyTest before running tests [OK]
Hint: Always install PyTest before running it in workflow [OK]
Common Mistakes:
Assuming command spelling is wrong
Ignoring PyTest installation step
Blaming GitHub Actions for test failures
5. You want to create a GitHub Actions workflow that runs PyTest on Python 3.10 and 3.11 versions. Which YAML snippet correctly sets up the Python versions and runs PyTest?
hard
A. jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.10, 3.11]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install pytest
- name: Run tests
run: pytest
B. jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.10
- name: Install dependencies
run: pip install pytest
- name: Run tests
run: pytest
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Run tests
run: pytest
C. jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.10, 3.11]
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: pip install pytest
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run tests
run: pytest
D. jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.10
- name: Run tests
run: pytest
Solution
Step 1: Identify YAML with matrix strategy and correct step order for multi-version testing
Use strategy.matrix to run on 3.10/3.11; checkout, then setup Python with ${{ matrix.python-version }}, install pytest, run tests.
Final Answer:
YAML snippet with matrix strategy and correct step order -> Option A