Files
learn-python3/notebooks/beginner/exercises/08_testing1_exercise.ipynb
2023-04-20 10:20:55 +03:00

83 lines
1.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Let's make sure pytest and ipytest packages are installed\n",
"# ipytest is required for running pytest inside Jupyter notebooks\n",
"import sys\n",
"\n",
"!{sys.executable} -m pip install pytest\n",
"!{sys.executable} -m pip install ipytest\n",
"\n",
"# These are needed for running pytest inside Jupyter notebooks\n",
"import ipytest\n",
"\n",
"ipytest.autoconfig()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Creating your first test case\n",
"There is an implementation for `get_divisible_by_five` function in the cell below. Your task is to create a test case for this function to verify that it works correctly.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": false
},
"outputs": [],
"source": [
"def get_divisible_by_five(numbers):\n",
" \"\"\"Returns a list of numbers which are divisible by five in the list got as an argument\"\"\"\n",
" result = []\n",
" for num in numbers:\n",
" if not num % 5:\n",
" result.append(num)\n",
"\n",
" return result"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%ipytest\n",
"\n",
"def test_get_divisible_by_five():\n",
" # Your implementation here\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}