-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
pytest --pdb is no longer working with Flask_testing #1932
Comments
@mbyt do you have an idea whats missing to have that detail work? |
Hi @niansheng, Is there a reason why unittests setUpClass and tearDownClass is not used? Note that it is supported also in python2.7. For me it looks like overwriting Basically I would not overwrite @classmethod
def setUpClass(cls):
cls._pre_setup()
@classmethod
def tearDownClass(cls):
cls._post_teardown() This is more pythonic / unittest standard. An alternative is to just directly use the pytest machinery. If you stay with unittest, an even more fine grained and better solution might be to use addCleanup in setUpClass which replaces the tearDownClass code. But probably I misunderstood the flask-testing code. By the way, using debug is actually documented, I did not recognize that before. |
Sorry, for the noise --- my previous comment is wrong. OK If you overwrite def debug(self):
self._pre_setup()
super(TestCase, self).debug()
self._post_teardown() Note: In order to enable debugging, I did not put that in a try and except here. |
Hi @mbyt Thanks for you reply and the suggestion. We tried this work around, it works fine with it own part. but we have a request mocker so unittests are running in the request mocker context.
By overwriting debug, it works. And this workaround is not too bad. Thanks |
Good to hear that you found a solution! Regarding the motivation for that change: When debugging standard unittests with |
Perhaps we should only stop calling I thought the use case for |
I did some debugging and I think that When calling From def debug(self):
"""Run the test without collecting errors in a TestResult"""
self.setUp()
getattr(self, self._testMethodName)()
self.tearDown()
while self._cleanups:
function, args, kwargs = self._cleanups.pop(-1)
function(*args, **kwargs) So if But bypassing All in all I'm leaning towards that this is correct behavior, but coming to the conclusion that this shouldn't have gone to |
Furthermore we could even add a |
@mbyt Thanks for the link. Actually I found the simply post morterm debugging issue too. The problem was the db had been dropped instead of GUI when exception happen. Thanks again for that PR, it could also address this problem. I used to add "ipdb" in the code before the exception raises as a workaround. @nicoddemus Thanks for you comments. But I am not sure what do you mean by "I think it is fine to pull it back from 3.0.3 and add it to 3.1.0." I usually add If the behavior is right, the overwriting the thanks |
Hi @niansheng,
Exactly, with #1890 this extra step of putting a "ipdb" before the exception should now be vanished; or in other words, post mortem debugging should work out of the box also in complex scenarios (where different kind of tearDowns act).
My conclusion is: If people overwrite unittest.TestCase |
I meant reverting that change for @mbyt perhaps we should add a note to the docs explaining your conclusion? |
thanks guys. I think this is a good way and right direction. I am sure Flask_testing framework can does something to follow to get that nice post-mortem debugging future. |
Just wanted to reference that I recently encountered the issue in Django pytest-dev/pytest-django#406 . Django flushes db between tests on |
The workaround is taken from the comments in pytest-dev/pytest#1932
- The workaround is taken from the comments in pytest-dev/pytest#1932 - It does not wrap the _pre_setup/_post_teardown calls in try/except clauses to allow exception to be raised for debugging purposes
- The workaround is taken from the comments in pytest-dev/pytest#1932 - It does not wrap the _pre_setup/_post_teardown calls in try/except clauses to allow exception to be raised for debugging purposes
- The workaround is taken from the comments in pytest-dev/pytest#1932 - It does not wrap the _pre_setup/_post_teardown calls in try/except clauses to allow exception to be raised for debugging purposes
Also relevant: #1977 |
A possibly tangential question - as a workaround, I've been trying to override debug() in my flask_testing
I'm overriding
which is coming from inside unittest's |
Also, cross-referencing jarus/flask-testing#94 |
Is this still an issue? This sounds really bad/wrong - it should rather skip only teardown when pdb is invoked actually, if at all. I think the main problem is rather: why is teardown being invoked before the debugger kicks in? |
Closing due to lack of feedback, feel free to re-open / follow up. |
For reference: #5996 removes calling |
Hi All
Recently we have problem to run "pytest --pdb" with our flask testcases. The testcases were fine until this change(4eeb475). The case is when we add --pdb option all the case failed with the same reason. "self.app is None", but if no "--pdb" then all tests pass.
By debugging, we found that this pre_setup function
https://github.com/jarus/flask-testing/blob/master/flask_testing/utils.py#L102 is called to setup _self.app.
But since the change, it calls the debug function instead of the Testcase which will skip the whole pre_setup function.
I tried to customise our own debug function to call pre_setup, but failed with further issues(request mocker). So I am wondering if I am doing right, or this is an issue I can address with flask_testing.
For now we just use previous version(3.0.1) of pytest, but we like to be as close as possible to the latest. Any advise will be appreciated. Thanks
Niansheng
The text was updated successfully, but these errors were encountered: