Skip to content
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

Make normal fixtures work with "yield" #1586

Conversation

nicoddemus
Copy link
Member

Did a quick experiment to see how hard would it be to implement #1461 to suggest working on it during the sprint... astonished to find out it was way too easy. 😲

Just ignore the yieldctx parameter and decide on the spot if we are a "yield fixture" based on whether or not the function is a generator does the trick nicely.

Almost all of the changes are related only to change the tests of yield_fixture to also test with plain fixture to prove this is working.

Missing:

  • Clean up the code (remove the need to pass yieldctx around);
  • Update docs and CHANGELOG;

Opening the PR to discuss if we should move this forward or not. @RonnyPfannschmidt, @hpk42, @The-Compiler what you guys think?

@nicoddemus nicoddemus changed the title Experiment to make normal fixtures work with "yield" [WIP] Experiment to make normal fixtures work with "yield" Jun 3, 2016
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 92.407% when pulling a0bbad6 on nicoddemus:issue-1461-merge-yield-fixture into b5bd4d9 on pytest-dev:features.

@nicoddemus
Copy link
Member Author

(quick note: AppVeyor is failing because of the "doctesting" env, which is already fixed in master)

@RonnyPfannschmidt
Copy link
Member

Looks neat, surprisingly simple, just wondering if this is to be considered a breaking api change art semver

@@ -2326,6 +2326,7 @@ def fail_fixturefunc(fixturefunc, msg):
pytrace=False)

def call_fixture_func(fixturefunc, request, kwargs, yieldctx):
yieldctx = is_generator(fixturefunc)
if yieldctx:
if not is_generator(fixturefunc):
fail_fixturefunc(fixturefunc,
Copy link
Member

@The-Compiler The-Compiler Jun 3, 2016

Choose a reason for hiding this comment

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

So I know this is a WIP, just adding this so we don't accidentally forget: Those lines aren't needed anymore now 😉

EDIT: Or should be changed to work again, as I pointed out in #1586 (comment)

@The-Compiler
Copy link
Member

Awesome! 👍

@RonnyPfannschmidt What would be the breaking change? I can only imagine two things:

  • A yield_fixture without a yield would now work instead of error out. We can change that to the old behaviour.
  • A fixture with a yield would now work instead of erroring the test. I don't think that's a backwards-incompatible change, as hopefully nobody would keep tests around which fail in that way 😉

@RonnyPfannschmidt
Copy link
Member

@The-Compiler true

@nicoddemus
Copy link
Member Author

Nice, I will continue to work on the PR then (clean it up and docs, mostly).

About the documentation, I plan to consider @fixture + yield as the recommended way of writing teardown fixture code and update all examples to use @fixture and yield where appropriate (those which don't have tear down code will be kept using return). So yield_fixture will be a footnote in the docs mentioned only as a historical fact. How do you guys feel about that?

A yield_fixture without a yield would now work instead of error out. We can change that to the old behaviour.

I see. We just have to consider that to keep this behavior we need to keep yieldctx around... I was hoping to remove that as this will cleanup the code quite a bit. Do you feel we really need this behavior?

@The-Compiler
Copy link
Member

The-Compiler commented Jun 3, 2016

About the documentation, I plan to consider @fixture + yield as the recommended way of writing teardown fixture code and update all examples to use @fixture and yield where appropriate (those which don't have tear down code will be kept using return). So yield_fixture will be a footnote in the docs mentioned only as a historical fact. How do you guys feel about that?

Sounds great to me!

I see. We just have to consider that to keep this behavior we need to keep yieldctx around... I was hoping to remove that as this will cleanup the code quite a bit. Do you feel we really need this behavior?

Hmm, that's a good point. On a second thought I guess we can do without it, as hopefully people will get away from using yield_fixture anyways.

@nicoddemus
Copy link
Member Author

Cleaned up the code and updated docs! 😁

@nicoddemus nicoddemus changed the title [WIP] Experiment to make normal fixtures work with "yield" Make normal fixtures work with "yield" Jun 8, 2016
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 92.405% when pulling a91d035 on nicoddemus:issue-1461-merge-yield-fixture into b5bd4d9 on pytest-dev:features.

@@ -211,7 +211,7 @@ but here is a simple overview:
You need to have Python 2.7 and 3.5 available in your system. Now
running tests is as simple as issuing this command::

$ python runtox.py -e linting,py27,py35
$ python3 runtox.py -e linting,py27,py35
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is already on master, cherry-picked here to see green builds. 😁

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 92.433% when pulling e2040f4 on nicoddemus:issue-1461-merge-yield-fixture into b5bd4d9 on pytest-dev:features.

@nicoddemus nicoddemus force-pushed the issue-1461-merge-yield-fixture branch from e2040f4 to bdc2996 Compare June 9, 2016 00:08
@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 92.433% when pulling bdc2996 on nicoddemus:issue-1461-merge-yield-fixture into 9232389 on pytest-dev:features.

@nicoddemus
Copy link
Member Author

Guys, would you like to merge this now or would you rather wait until the sprint?

@RonnyPfannschmidt RonnyPfannschmidt merged commit feeee28 into pytest-dev:features Jun 14, 2016
@The-Compiler
Copy link
Member

I'm a bit late to the party, but LGTM, and thanks for the great work! I think this definitely simplifies things a lot. 👍

@nicoddemus nicoddemus deleted the issue-1461-merge-yield-fixture branch June 16, 2016 10:58
olegpidsadnyi pushed a commit to pytest-dev/pytest-bdd that referenced this pull request Jun 21, 2016
In pytest-dev/pytest#1586 the "yieldctx"
argument to FixtureDef was removed.

This uses utils.get_args to check if it's needed or not so pytest-bdd
works on pytest versions before and after that PR.
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