Skip to content

Commit 074390b

Browse files
committed
Fix: do not replace less than
1 parent 3b53db1 commit 074390b

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

_sources/UnitTesting/TestingWithpytest.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ Here's an example of how it works:
6666
except Exception as e:
6767
self.assertEqual(item + " failed", item + " passed", item + " failed: " + str(e))
6868

69-
pyTests().main()
69+
pyTests().main()
70+
7071

71-
7272
.. test:
7373
7474
success = True
@@ -82,15 +82,15 @@ Here's an example of how it works:
8282
8383
if success:
8484
print("All tests passed!")
85-
85+
8686
This code example defines two functions: the function to be tested, ``round6``, and a function named ``test_round6``
8787
that contains unit test code. When using the pytest approach, you write your unit test as a function whose name must
8888
start with the prefix ``test_``. Inside the function, you write normal assert statements to test the desired function.
8989
Notice that you do not write a line to *call* the unit test function. Instead, when you launch pytest to run the unit
90-
tests, pytest scans your script and executes only the functions with the prefix ``test_``.
90+
tests, pytest scans your script and executes only the functions with the prefix ``test_``.
9191

9292
This ActiveCode environment simulates pytest by scanning for and executing functions with a ``test_`` prefix when you
93-
click **Run**. Go ahead and try it - rename the test_round6 function to ``test_itworks`` and try running the test again.
93+
click **Run**. Go ahead and try it - rename the test_round6 function to ``test_itworks`` and try running the test again.
9494

9595
Organizing pytest Functions
9696
---------------------------
@@ -121,11 +121,11 @@ Using pytest
121121
------------
122122

123123
To use pytest, you must first install it using the **pip** command. Open your computer's command line window
124-
(not the Python interpreter) and enter the following command to install:
124+
(not the Python interpreter) and enter the following command to install:
125125

126126
* Windows::
127127

128-
pip install pytest
128+
pip install pytest
129129

130130
* Mac/Linux::
131131

@@ -151,7 +151,7 @@ When you run the pytest command and an assertion fails, you see a report like th
151151
> assert round6(8.5) == 8
152152
E assert 9 == 8
153153
E + where 9 = round6(8.5)
154-
154+
155155
myround.py:8: AssertionError
156156

157157
Let's take a closer look at this report to understand what it's telling you.
@@ -168,15 +168,15 @@ Let's take a closer look at this report to understand what it's telling you.
168168
E + where 9 = round6(8.5)
169169

170170
This indicates that the call to ``round6(8.5)`` returned the value 9, instead of the value 8.
171-
The value ``9`` is the actual result of the function. Knowing the value actually produced by
171+
The value ``9`` is the actual result of the function. Knowing the value actually produced by
172172
the function can help you to troubleshoot the bug and correct the problem.
173173

174174
Integrated Unit Testing with pytest
175175
------------------------------------
176176

177177
When you use the pytest framework, you can include pytest test functions in your main program, along with the rest of
178178
your program code. This allows you to keep your tests together with the functions that they test, and you can run either
179-
your program (using the python command) or the unit tests (using the pytest command).
179+
your program (using the python command) or the unit tests (using the pytest command).
180180

181181
Take a look at this example that shows a function (``round6``, containing a bug), together with a
182182
unit test function (``test_round6``), and a main program that uses ``round6``:
@@ -234,7 +234,7 @@ sense, just remember: in order for pytest to work correctly, any code that is pa
234234
"""
235235
~~~~
236236
# Write a pytest unit test function named ``test_grade``
237-
237+
238238

239239
====
240240
from unittest.gui import TestCaseGui
@@ -247,7 +247,7 @@ sense, just remember: in order for pytest to work correctly, any code that is pa
247247
def grade(score):
248248
global illegal, testA, testB, testF
249249

250-
if score > 100 or score < 0:
250+
if score > 100 or score < 0:
251251
illegal = True
252252
return ''
253253
elif score >= 90:
@@ -276,13 +276,13 @@ sense, just remember: in order for pytest to work correctly, any code that is pa
276276

277277
The following is a suggested pytest unit test.
278278

279-
.. sourcecode::
280-
279+
.. sourcecode::
280+
281281
def test_grade():
282282
assert grade(92) == 'A'
283283
assert grade(85) == 'B'
284284
assert grade(69) == 'F'
285285

286-
286+
287287

288288

0 commit comments

Comments
 (0)