Skip to content

Commit f2ba8d7

Browse files
committed
Fix typo and add suggestion from review
1 parent afe847e commit f2ba8d7

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

doc/en/fixture.rst

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ marked ``smtp`` fixture function. Running the test looks like this::
7373
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
7474
rootdir: $REGENDOC_TMPDIR, inifile:
7575
collected 1 items
76-
76+
7777
test_smtpsimple.py F
78-
78+
7979
======= FAILURES ========
8080
_______ test_ehlo ________
81-
81+
8282
smtp = <smtplib.SMTP object at 0xdeadbeef>
83-
83+
8484
def test_ehlo(smtp):
8585
response, msg = smtp.ehlo()
8686
assert response == 250
8787
> assert 0 # for demo purposes
8888
E assert 0
89-
89+
9090
test_smtpsimple.py:11: AssertionError
9191
======= 1 failed in 0.12 seconds ========
9292

@@ -169,7 +169,7 @@ function (in or below the directory where ``conftest.py`` is located)::
169169
response, msg = smtp.ehlo()
170170
assert response == 250
171171
assert b"smtp.gmail.com" in msg
172-
assert 0 # for demo purposes
172+
assert 0 # for demo purposes
173173

174174
def test_noop(smtp):
175175
response, msg = smtp.noop()
@@ -184,32 +184,32 @@ inspect what is going on and can now run the tests::
184184
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
185185
rootdir: $REGENDOC_TMPDIR, inifile:
186186
collected 2 items
187-
187+
188188
test_module.py FF
189-
189+
190190
======= FAILURES ========
191191
_______ test_ehlo ________
192-
192+
193193
smtp = <smtplib.SMTP object at 0xdeadbeef>
194-
194+
195195
def test_ehlo(smtp):
196196
response, msg = smtp.ehlo()
197197
assert response == 250
198198
assert b"smtp.gmail.com" in msg
199199
> assert 0 # for demo purposes
200200
E assert 0
201-
201+
202202
test_module.py:6: AssertionError
203203
_______ test_noop ________
204-
204+
205205
smtp = <smtplib.SMTP object at 0xdeadbeef>
206-
206+
207207
def test_noop(smtp):
208208
response, msg = smtp.noop()
209209
assert response == 250
210210
> assert 0 # for demo purposes
211211
E assert 0
212-
212+
213213
test_module.py:11: AssertionError
214214
======= 2 failed in 0.12 seconds ========
215215

@@ -260,7 +260,7 @@ Let's execute it::
260260

261261
$ pytest -s -q --tb=no
262262
FFteardown smtp
263-
263+
264264
2 failed in 0.12 seconds
265265

266266
We see that the ``smtp`` instance is finalized after the two
@@ -290,7 +290,7 @@ because the ``smtp`` object automatically closes when
290290
the ``with`` statement ends.
291291

292292
Note that if an exception happens during the *setup* code (before the ``yield`` keyword), the
293-
*teardown* code (after the ``yield``) will not be called.
293+
*teardown* code (after the ``yield``) will not be called.
294294

295295

296296
.. note::
@@ -302,7 +302,7 @@ Note that if an exception happens during the *setup* code (before the ``yield``
302302

303303
An alternative option for executing *teardown* code is to
304304
make use of the ``addfinalizer`` method of the `request-context`_ object to register
305-
finalization functions.
305+
finalization functions.
306306

307307
Here's the ``smtp`` fixture changed to use ``addfinalizer`` for cleanup:
308308

@@ -321,7 +321,8 @@ Here's the ``smtp`` fixture changed to use ``addfinalizer`` for cleanup:
321321
request.addfinalizer(fin)
322322
return smtp # provide the fixture value
323323
324-
Both ``yield`` and ``addfinalizer`` methods work similar by calling their code after the test
324+
325+
Both ``yield`` and ``addfinalizer`` methods work similarly by calling their code after the test
325326
ends, but ``addfinalizer`` has two key differences over ``yield``:
326327

327328
1. It is possible to register multiple finalizer functions.
@@ -340,7 +341,8 @@ ends, but ``addfinalizer`` has two key differences over ``yield``:
340341
return r
341342

342343
In the example above, if ``"C28"`` fails with an exception, ``"C1"`` and ``"C3"`` will still
343-
be properly closed.
344+
be properly closed. Of course, if an exception happens before the finalize function is
345+
registered then it will not be executed.
344346

345347

346348
.. _`request-context`:
@@ -371,7 +373,7 @@ again, nothing much has changed::
371373

372374
$ pytest -s -q --tb=no
373375
FFfinalizing <smtplib.SMTP object at 0xdeadbeef> (smtp.gmail.com)
374-
376+
375377
2 failed in 0.12 seconds
376378

377379
Let's quickly create another test module that actually sets the
@@ -439,51 +441,51 @@ So let's just do another run::
439441
FFFF
440442
======= FAILURES ========
441443
_______ test_ehlo[smtp.gmail.com] ________
442-
444+
443445
smtp = <smtplib.SMTP object at 0xdeadbeef>
444-
446+
445447
def test_ehlo(smtp):
446448
response, msg = smtp.ehlo()
447449
assert response == 250
448450
assert b"smtp.gmail.com" in msg
449451
> assert 0 # for demo purposes
450452
E assert 0
451-
453+
452454
test_module.py:6: AssertionError
453455
_______ test_noop[smtp.gmail.com] ________
454-
456+
455457
smtp = <smtplib.SMTP object at 0xdeadbeef>
456-
458+
457459
def test_noop(smtp):
458460
response, msg = smtp.noop()
459461
assert response == 250
460462
> assert 0 # for demo purposes
461463
E assert 0
462-
464+
463465
test_module.py:11: AssertionError
464466
_______ test_ehlo[mail.python.org] ________
465-
467+
466468
smtp = <smtplib.SMTP object at 0xdeadbeef>
467-
469+
468470
def test_ehlo(smtp):
469471
response, msg = smtp.ehlo()
470472
assert response == 250
471473
> assert b"smtp.gmail.com" in msg
472474
E AssertionError: assert b'smtp.gmail.com' in b'mail.python.org\nSIZE 51200000\nETRN\nSTARTTLS\nENHANCEDSTATUSCODES\n8BITMIME\nDSN\nSMTPUTF8'
473-
475+
474476
test_module.py:5: AssertionError
475477
-------------------------- Captured stdout setup ---------------------------
476478
finalizing <smtplib.SMTP object at 0xdeadbeef>
477479
_______ test_noop[mail.python.org] ________
478-
480+
479481
smtp = <smtplib.SMTP object at 0xdeadbeef>
480-
482+
481483
def test_noop(smtp):
482484
response, msg = smtp.noop()
483485
assert response == 250
484486
> assert 0 # for demo purposes
485487
E assert 0
486-
488+
487489
test_module.py:11: AssertionError
488490
------------------------- Captured stdout teardown -------------------------
489491
finalizing <smtplib.SMTP object at 0xdeadbeef>
@@ -555,7 +557,7 @@ Running the above tests results in the following test IDs being used::
555557
<Function 'test_noop[smtp.gmail.com]'>
556558
<Function 'test_ehlo[mail.python.org]'>
557559
<Function 'test_noop[mail.python.org]'>
558-
560+
559561
======= no tests ran in 0.12 seconds ========
560562

561563
.. _`interdependent fixtures`:
@@ -594,10 +596,10 @@ Here we declare an ``app`` fixture which receives the previously defined
594596
cachedir: .cache
595597
rootdir: $REGENDOC_TMPDIR, inifile:
596598
collecting ... collected 2 items
597-
599+
598600
test_appsetup.py::test_smtp_exists[smtp.gmail.com] PASSED
599601
test_appsetup.py::test_smtp_exists[mail.python.org] PASSED
600-
602+
601603
======= 2 passed in 0.12 seconds ========
602604

603605
Due to the parametrization of ``smtp`` the test will run twice with two
@@ -663,40 +665,40 @@ Let's run the tests in verbose mode and with looking at the print-output::
663665
cachedir: .cache
664666
rootdir: $REGENDOC_TMPDIR, inifile:
665667
collecting ... collected 8 items
666-
668+
667669
test_module.py::test_0[1] SETUP otherarg 1
668670
RUN test0 with otherarg 1
669671
PASSED TEARDOWN otherarg 1
670-
672+
671673
test_module.py::test_0[2] SETUP otherarg 2
672674
RUN test0 with otherarg 2
673675
PASSED TEARDOWN otherarg 2
674-
676+
675677
test_module.py::test_1[mod1] SETUP modarg mod1
676678
RUN test1 with modarg mod1
677679
PASSED
678680
test_module.py::test_2[1-mod1] SETUP otherarg 1
679681
RUN test2 with otherarg 1 and modarg mod1
680682
PASSED TEARDOWN otherarg 1
681-
683+
682684
test_module.py::test_2[2-mod1] SETUP otherarg 2
683685
RUN test2 with otherarg 2 and modarg mod1
684686
PASSED TEARDOWN otherarg 2
685-
687+
686688
test_module.py::test_1[mod2] TEARDOWN modarg mod1
687689
SETUP modarg mod2
688690
RUN test1 with modarg mod2
689691
PASSED
690692
test_module.py::test_2[1-mod2] SETUP otherarg 1
691693
RUN test2 with otherarg 1 and modarg mod2
692694
PASSED TEARDOWN otherarg 1
693-
695+
694696
test_module.py::test_2[2-mod2] SETUP otherarg 2
695697
RUN test2 with otherarg 2 and modarg mod2
696698
PASSED TEARDOWN otherarg 2
697699
TEARDOWN modarg mod2
698-
699-
700+
701+
700702
======= 8 passed in 0.12 seconds ========
701703

702704
You can see that the parametrized module-scoped ``modarg`` resource caused an

0 commit comments

Comments
 (0)