-
-
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 not returning errors where I expect them #2677
Comments
what is the output of your test run? and what is the name of your test file. make sure the name of the file begins with |
unless im mistaken, that kind of usage should be |
@dhoomakethu The output can be seen in the attached results. Note that I use a custom plugin to print out whether or not a section passed (i.e. setup passed, call failed, teardown passed). The name of the file is just "test.py". @RonnyPfannschmidt Can you please elaborate/point me toward the proper resource? I'm unfamiliar with what you mean |
@ShmuelTreiger i reviewed, and this is a necessary mismatch for unittest compatibility unittest setup method cannot be part of pytest setup/teardown machinery due to massive differences in the control flow @nicoddemus is this already documented somewhere, i recall you detailing out that part of the docs lately |
@RonnyPfannschmidt I clarified a few points in the latest
You got it right, the problem here is that all At some point someone suggested (I think it was @hpk42) an alternative implementation by implementing For illustration, this simple class Test(TestCase):
def setUp(self):
self.protocol = Protocol()
def tearDown(self):
self.protocol.close()
def test_protocol(self):
... Would look like this behind the scenes after collection: class Test(TestCase):
@pytest.fixture(autouse=True)
def _internal_pytest_setup_teardown(self):
# injected by pytest automatically during collection
self.setUp()
yield
self.tearDown()
def setUp(self):
self.protocol = Protocol()
def tearDown(self):
self.protocol.close()
def test_protocol(self):
... This would make
@ShmuelTreiger please let us know if you have more questions or some of the details are not clear. 👍 |
I understand. Thank you so much for the thorough and detailed response. Really helps me conceptualize and understand what's going on here. Also, I hadn't come across the unittest page yet, and it looks super helpful, so thank you for that as well. |
Great, glad it was useful! |
When I run the following code, pytest gives me a failure. From my understanding based on the docs and a question I asked on this plugin it should be returning an error.
I made a custom plugin just for this problem and the root of the issue seems to be that both setup and teardown pass, while call fails, hence why it's registering as a failure and not an error. I guess the better question is why doesn't setup fail?
I'm running on windows using pytest 3.1.2. Pip list shouldn't matter, though I will note that I don't have the above mentioned plugin installed and that my custom plugin only prints information.
Sorry, this might not be a bug, this might just be my misunderstanding, so I decided to post both here and on stackoverflow. Thank you for the help.
The text was updated successfully, but these errors were encountered: