Skip to content

fixture docs: highlight difference between yield and addfinalizer methods #2511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2017

Conversation

nicoddemus
Copy link
Member

cc @samjl

Fix #2508

request.addfinalizer(fin)
return smtp # provide the fixture value

Both ``yield`` and ``addfinalizer`` methods work similar by calling their code after the test
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...methods work "similarly" by calling...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops thanks.

r = []
for port in ('C1', 'C3', 'C28'):
equip = connect(port)
request.addfinalizer(equip.disconnect)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I think I would add a note to say that if any code raises an exception before the teardown function is registered with addfinalizer then the teardown function is not executed (even though it's obvious)?

In my specific case the first thing I do in the fixture is register the teardown function with addfinalizer.

Nice worked example though!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.133% when pulling afe847e on nicoddemus:addfinalizer-docs into 8c3c430 on pytest-dev:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.133% when pulling f2ba8d7 on nicoddemus:addfinalizer-docs into 8c3c430 on pytest-dev:master.

@RonnyPfannschmidt RonnyPfannschmidt merged commit 4a62102 into pytest-dev:master Jun 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants