-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
No warning when class is skipped due to __init__ #410
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
Comments
Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42): Yikes. Sorry you stumbled over this. Indeed i think we need to have a little warning subsystem so that the result at the end would say "1 passed, ..., 1 WARNING" and then have a switch to present those warnings. So i agree with your suggestion to present warnings. |
Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt): what version of pytest? recently we do cause a skip for those |
Original comment by Sam Thursfield (BitBucket: samthursfield, GitHub: samthursfield): Ronny: it's version 2.5.2 of pytest |
Original comment by Torsten Landschoff (BitBucket: bluehorn, GitHub: bluehorn): Yesterday the same thing happened to us: Somebody added a init to a test class and somehow all the tests in the class were skipped. We finally found the reason here from http://pytest.org/latest/goodpractises.html?highlight=discovery#conventions-for-python-test-discovery:
Is there any reason why a test class can not have an init method without arguments? Interestingly enough, it is possible to override new in a test class. Observe:
Compare this with overriding new:
What's also interesting is the calling sequence:
So the dunder new method is called three times during collection of the two tests (unexpected to me), while when running the tests each method gets a new instance of the class (as expected). I would prefer that dunder init (without arguments) works just as dunder new. |
👍 |
Current # content of test_foo.py
class Test:
def __init__(self):
pass
def test_foo(self):
pass
def test_bar():
pass
(And the footer "1 passed, 1 warnings" even appears in yellow) Running with
So I'm closing this issue. If people would like to discuss if having an |
What's the reason a TestClass with I have a hierarchy of objects and want to emulate this hierarchy on the test side, so that each |
just stumbled upon this behaviour. my question is:
my preferable way would be to avoid changing the code of the Test classes themselves as it still needs to be runnable via the legacy runner and if pytest could collect and run those tests by first running the |
Perhaps we can relax this restriction a bit and allow |
I'm not understanding why having a bare |
I think it is a matter of that |
someone should demonstrate a good use-case first in particular one that's not covered better with fixtures or xunit setup methods,else i'm -1 |
to elaborate on that - https://github.com/pytest-dev/pytest/blob/master/src/_pytest/python.py#L194 only opts out of unsafe classes if there is no result, so a testsuite in transition is perfectly fine to have a own |
I think it would consume a lot of time trying to find a superior use case, as there may not be one. I only stumbled on this warning while transitioning from # Old -> warning
class TestData:
def __init__(self):
self.data = DATA
...
# New -> fixed
class TestData:
data = DATA
... Luckily the fix was simple, but since the first approach is a valid way to make regular classes (even in I don't mind improving idioms provided the rationale is clear and generally pythonic. Many thanks. |
I believe this requirement stems from the fact that I also suspect that
Sure, they are mentioned here:
Not other requirements other than that are needed I believe. In the end, we could implement the capability of definining |
Was also stuck on this issue for a while! |
@nicoddemus imho class TestFoo:
def __init__(self, tmp_path, postgres):
self.path = tmp_path / "foo"
self.data = some_data() maybe it also makes sense for attr.s/dataclasses: @attr.ib(frozen=True)
class TestFoo:
tmp_path = attr.ib()
postgres = attr.ib()
def test_foo(self):
path = self.tmp_path / "foo" although notably less powerful, as you cannot create |
@graingert all of those examples can be sorted by a class level fixture, with the advantage of zero ambiguity |
Addressed is an issue described at pytest-dev/pytest#410 .
Originally reported by: Sam Thursfield (BitBucket: samthursfield, GitHub: samthursfield)
I just spent a whole afternoon trying to work out why a testsuite class was being skipped. It turns out it was because there was an init() function in the class.
Py.test doesn't give any kind of warning as to why the function was skipped; it took going through the code and attaching 'pdb' to find the exception that says 'class test_htol_results.TestHtolResultRecords with init won't get collected'. OK, if I'd read the documentation from start to finish I'm sure I'd have known :-) But if Py.test had outputted a warning as to why the testsuite was skipped it would have saved me a lot of time.
The text was updated successfully, but these errors were encountered: