-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Use fixtures to invoke xunit-style fixtures #4091
Use fixtures to invoke xunit-style fixtures #4091
Conversation
src/_pytest/python.py
Outdated
teardown_module = _get_xunit_setup_teardown(self.obj, "teardown_module") | ||
if teardown_module is not None: | ||
self.addfinalizer(teardown_module) | ||
# def setup(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the comments, dead code should go, we have history so we don't have to keep zombies 😈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh definitely. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to use fixture factory parsing to add the fixtures as needed?
80e890b
to
5ec4e42
Compare
Codecov Report
@@ Coverage Diff @@
## features #4091 +/- ##
============================================
- Coverage 95.75% 95.38% -0.37%
============================================
Files 111 111
Lines 24678 24737 +59
Branches 2446 2455 +9
============================================
- Hits 23630 23595 -35
- Misses 740 820 +80
- Partials 308 322 +14
Continue to review full report at Codecov.
|
5ec4e42
to
954de66
Compare
Cool, now all tests pass under the new implementation. TODO:
|
954de66
to
7d53b5b
Compare
Finally ready for review 🎉 |
7d53b5b
to
0f918b1
Compare
Sorry for the question on PR, but here it goes... I'm moving an existing unittest code base to pytest. This PR suggests you're trying to move all that setup to fixtures which I assume should not require us to hack around the old behavior. Anyway, the question(s):
Again, sorry for the question in the PR and for the long explanation around it. |
This is exactly the problem this PR tries to solve. 😁 With it,
Probably quite soon after this gets merged. I don't understand though why you mention
Which "setup fixture" you mean? Could you please clarify? |
Superb!
Looked like a blocker for the inclusion of this on 4.1
Read your code and your reply. Its no longer a question. Session scoped fixtures are evaluated before class based fixes. 🎉 Can't wait for this to get in the wild!!! Thank You, and the rest of the PyTest contributors for making test writing something more joyful. |
@s0undt3ch oh I see, thanks. I thought you were talking about your own code, not about this PR. 😅 |
@RonnyPfannschmidt @asottile @blueyed gentle ping. 😁 After this, #4280, and #4511 gets merged, I believe we are ready for a |
oh, I trust @RonnyPfannschmidt's judgement on this one and so I removed it from my "to review" queue 😆 -- let me know if you want another pair of eyes on it |
🎉 |
It should be soon, likely next week or the next. 👍 |
It looks like pytest-dev/pytest#4091 broke the setUpTestData method, meaning all fixture data was being inserted for each test method. This is not a fix. If pytest doesn't provide a fix, we'll have to look at using it's session fixtures, or moving tests to full pytest functions – this would be good in the long term (it provides nicer debugging and less boilerplate), but would be a huge job.
It looks like pytest-dev/pytest#4091 broke the setUpTestData method, meaning all fixture data was being inserted for each test method. This is not a fix. If pytest doesn't provide a fix, we'll have to look at using it's session fixtures, or moving tests to full pytest functions – this would be good in the long term (it provides nicer debugging and less boilerplate), but would be a huge job.
WIP for #3094.
Unfortunately I'm not able to get this to work with yield tests, their expectations about when
setup_*
functions are called break when we move thesetup_*
call to fixtures.Consider this test (simplified from
test_runner_xunit.py::test_func_generator_setup
):This is what happens on
master
: during collection,setup_module
is called (byNode.setup()
), thentest_one
is called to generate the internal yield test functioncheck
. For this reason, theassert x == []
line at the beginning oftest_one
works.What this PR does is to inject an autouse module-scoped fixture which calls
setup_module
. The problem is that this changes the semantics of yield-tests:test_one
is still called during collection to generate thecheck
test, butsetup_module
has not been called yet because it will be called by a fixture later during the runtest phase, so the lineassert x == []
fails.I don't see a way around this, so I'm afraid we will have to post-pone this for pytest 4.1, when we finally remove yield-tests.