Skip to content

Commit a614370

Browse files
fix testing
1 parent 92ba52d commit a614370

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

book/10_testing.ipynb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"**Refactoring** \n",
5555
"When we want to modify working code, since tests can give us some degree of confidence that we are not breaking the functionality, for example, while optimizing running time.\n",
5656
"\n",
57-
"\n",
5857
"**Documentation** \n",
5958
"Tests can serve as a way to communicate other people (our ourselves) the expected behaviour of our code."
6059
]
@@ -129,7 +128,13 @@
129128
" return value * value\n",
130129
"```\n",
131130
"\n",
132-
"So let's create a directory (next to `src`) called `tests` and make a file called `tests/test_square.py` including our previous `test_square` code:\n",
131+
"So let's create a directory (next to `src`) called `tests` and make a file called `tests/test_square.py` including our previous `test_square` code.\n",
132+
"\n",
133+
"If you've been following along, your project should look more or less like this:\n",
134+
"\n",
135+
"![](./images/tree-3.png){width=150}\n",
136+
"\n",
137+
"Now put this content in `test_square.py`:\n",
133138
"\n",
134139
"```python\n",
135140
"from pycourse.square import square # Import function from source code test\n",
@@ -141,9 +146,9 @@
141146
" assert square(5) == 25\n",
142147
"```\n",
143148
"\n",
144-
"Notice that we do not call the function, we just define it.\n",
145149
"\n",
146150
":::{.callout-important}\n",
151+
"Notice that we do not call the function, we just define it.\n",
147152
"The file must be called `test_*.py` or `*_test.py` for pytest to discover it and the unit tests must start with `test_`.\n",
148153
":::\n",
149154
"\n",
@@ -250,7 +255,7 @@
250255
"source": [
251256
"## Exercises\n",
252257
"1) Modify the function `square` in `square.py` so that it returns `value * value * 2` and run the test again. Pay close attention to the error messages and the diffs!\n",
253-
"2) Write a function called `reverse_str` that takes a string and returns the reversed version, eg \"hola\" -> \"aloh\". Write a unit test and make sure the tests pass. Think about covering corner cases in your tests.S\n",
258+
"2) Write a function called `reverse_str` that takes a string and returns the reversed version, eg \"hola\" -> \"aloh\". Write a unit test and make sure the tests pass. Think about covering corner cases in your tests.\n",
254259
"3) Make the function `reverse_str` strict to only accept strings as input and throw an error if another type is passed. Write a unit test that covers both the \"happy path\" and the \"error path\"."
255260
]
256261
}

book/images/tree-3.png

21 KB
Loading

0 commit comments

Comments
 (0)