Skip to content

Add a failing unittest case when using --pdb option #406

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
Nov 21, 2016

Conversation

asfaltboy
Copy link
Contributor

@asfaltboy asfaltboy commented Oct 24, 2016

Here's a failing test for #405, tests on travis-ci and tox pass. This helped to isolate it to occurring on latest pytest==3.0.3, probably has something to do with the pdb changes in the last minor releases. Specifically, changelog for 3.0.2 includes merge of PR pytest-dev/pytest#1890:

Do not call tearDown and cleanups when running tests from unittest.TestCase subclasses with --pdb enabled. This allows proper post mortem debugging for all applications which have significant logic in their tearDown machinery (#1890). Thanks @mbyt for the PR.

In essence, it's not a bad change; but, when combined with --reuse-db or when setUp create unique Django objects this fails hard.

I guess one way, would be to re-enable this cleanup for pytest-django only.

But, to be honest, not sure how many more devs may spend hours looking for their missing tearDown code. On the other hand, I myself have suffered from "early cleanUp when using pdb". Hmmm, maybe there is a better way.

Other users have noted this can cause issues at pytest-dev/pytest#1932

@blueyed
Copy link
Contributor

blueyed commented Oct 24, 2016

Can you merge/cherry-pick #400 into this, so it fails here, too, please?

@asfaltboy
Copy link
Contributor Author

Added a quick workaround in latest commit d5696a2 ; this is basically copy-pasta of django.test.testcases.TestCase.__call__ sans try/except wrappers.

self._post_teardown()

cls.debug = _cleaning_debug

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a comment/doc!

It was mentioned to report it for Django itself also.. has that been done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment added in 74bef8d. I'm not sure this deserves mention in docs (besides maybe in the changelog). I'll submit a bug report with Django when I get a chance.

@asfaltboy
Copy link
Contributor Author

Django ticketed opened, for back ref: https://code.djangoproject.com/ticket/27391

@adamchainz
Copy link
Member

@blueyed I didn't get around to opening the Django ticket as I said I would in pytest-dev/pytest#1977 ... thanks @asfaltboy !

@pelme pelme force-pushed the feature/pdb-failure branch from 74bef8d to 50d17c6 Compare November 21, 2016 13:54
- 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
@pelme pelme force-pushed the feature/pdb-failure branch from 50d17c6 to 284af35 Compare November 21, 2016 13:56
@pelme pelme merged commit 3d71b6f into pytest-dev:master Nov 21, 2016
@pelme
Copy link
Member

pelme commented Nov 21, 2016

Thanks for all debugging! I've merged this and will soon put out a 3.1.1 release which contains this fix!

mfa pushed a commit to aexeagmbh/pytest-django that referenced this pull request May 17, 2017
timb07 pushed a commit to timb07/pytest-django that referenced this pull request May 26, 2018
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