Pytest/unit testing tasks
Welcome Detective!
This repository is your training ground to master pytest and learn the art of finding bugs through testing.
Hey Detective!
Before you can join the elite Bug Hunt Squad, you must first pass your Assert Academy Training.
Your mission is to explore and master different types of assertions by writing small test cases.
This will prepare you for the real investigation in Level 2.
1️Install pytest
Pytest Installation Guide
2️Learn your toolkit
Pytest Assertions Documentation
3️Your Tasks
Write pytest test cases for these functions:
- A function to add two numbers.
- A function to check if a number is even or odd.
- A function to print the first element of a list.
- A function to divide two numbers.
- A function with two parameters (
textandkeyword) that checks if the keyword exists in the text.
Use different assertions like assert, assertEqual, assertIsNone, assertGreater, assertLess, etc. to test:
- Normal cases
- Error cases
- Edge cases
OK Rookie,
Now you’ve completed your Academy Training and mastered the art of pytest assertions.
Here is a test assignment for you.
The Chief suspects that someone has slipped buggy logic into our mystery program.
The code may or may not contain logical errors.
- You will be given a buggy program:
schoolBounty.py - Your job is to catch every bug by writing proper pytest tests.
- Document your findings.
- Remember to check:
- Normal cases (average/expected inputs)
- Lower limit cases
- Upper limit cases
- Error cases (invalid input, empty values, etc.)
This is your next task whereAmI.py
This device can:
- Fetch the user’s current location using their IP address.
- Plot the location on a live interactive map.
But beware — while the gadget is powerful, the Agency suspects it is also bug-prone.
Your mission: hunt down the flaws by writing pytest tests and ensuring the gadget can’t be exploited. Then, improve the device based on your test findings that is you can make changes based on the test results to the code to make it better.
Clone this repository and set up your environment:
# Create virtual environment
python3 -m venv venv
# Activate venv (Linux)
source venv/bin/activate
# Install dependencies
pip install requests
pip install foliumNice work Detective!!
One last task — but this time you need to build the software yourself.
The Governor of our city is asking for a tool that will give live weather updates of the place he wants.
Your mission is to build a Weather Application in Python and then test it like a pro.
- Build a command-line (terminal) application (UI is not required).
- The program should:
-
Ask the user for their current city (where they are from).
- Fetch and display the weather for that city.
-
Ask the user for the destination city (the place they want to visit).
- Fetch and display the weather for that city.
-
After displaying both, ask:
Do you want to check the weather of another place? (yes/no)- If the user types yes, repeat step 2.
- If the user types no, exit the program.
-
Test the code that you wrote.
- City Name
- Country
- Temperature (°C)
- Humidity (%)
- Weather Description (e.g., "clear sky", "rainy")
Enter your city: Delhi
Weather in Delhi, IN:
Temperature: 30°C
Humidity: 40%
Condition: clear sky
Enter the city you want to visit: London
Weather in London, GB:
Temperature: 18°C
Humidity: 70%
Condition: light rain
Do you want to check the weather of another place? (yes/no): yes
Enter the city: Paris
Weather in Paris, FR:
Temperature: 20°C
Humidity: 60%
Condition: cloudy
Do you want to check the weather of another place? (yes/no): no
Exiting the program...