-
-
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
Fixture params not accessible inside the fixture, not getting called multiple times. #447
Comments
Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt): not supported on unittest subclasses try a autouse fixture or go for non-unittest |
Original comment by Paul Oswald (BitBucket: poswald, GitHub: poswald): I can't get autouse to work either. Of course, I could go for non-unittest for new code but I already have hundreds of tests that use Can you think of a way to allow unittest subclass methods to still be parameterized by py.test? a custom plugin? |
Original comment by Jurko Gospodnetić (BitBucket: jurko, GitHub: jurko): Just a thought... how about working around it with something like this:
You can use You just replace Also, I do not think this behaviour is anything unittest specific. I tested it using a regular pytest test class (just an ordinary class whose name starts with I think the main problem you are running into here is that with pytest, a test class method can only access its fixture if a reference to it is passed as an explicitly specified argument. pytest does not attempt to store a reference to the fixture in a test object's attribute. Hope this helps. Best regards, |
Original comment by Jurko Gospodnetić (BitBucket: jurko, GitHub: jurko): @poswald - I do not really get what you meant to say by:
I get the following tests collected in my example whether or not I access
so both test methods get collected twice - once for each fixture parameter. Exactly as I would expect them to. Best regards, |
Original comment by Paul Oswald (BitBucket: poswald, GitHub: poswald): Thanks for the suggestion and opening that issue for the docs. Sorry I'm not being clear enough. The issue with that is that it no longer works if you inherit from TestCase.
As Ronny said above, this is mostly by design. (as explained in the note at the bottom of the docs. I respect that design decision although I don't agree with it. (I think that if a developer explicitly marks a method with a decorator and that breaks the unittest API contract, then it's the developer's fault. I would rather the py.test let me take responsibility for that.) My problem is that I have a ton of classes (TestCase, pythonpaste WebTest, etc..) that already break the unittest style by being parametrized via a nose plugin and I'm trying to find a way to disable or work around this py.test safety mechanism. Mostly, I do think this issue is resolved because I understand how it works now and it's basically 'as designed'. It just doesn't solve my problem. Right now I'm investigating if I can write a new unittest plugin to replace the built in one that works exactly like it but doesn't have this feature.. |
Originally reported by: Paul Oswald (BitBucket: poswald, GitHub: poswald)
Parametrize decorator will not pass parameters into methods that are on subclasses of TestCase. There is a note at the bottom of http://pytest.org/latest/unittest.html#autouse-fixtures-and-accessing-other-fixtures explaining that this behaviour is intentional. I fully understand the logic behind that but I have quite a few tests that already are written in a way such that the methods accept (self, data) args by using a nose plugin. I need a function that works exactly like the parametrize decorator but will call TestCase methods.
In an attempt to work around this issue, I created the following proof of concept but it seems to have some issues:
When this runs request.param is not defined. Also, request.param is mentioned in the docs but not really listed in the request api.
Also, even if you don't try to access request.param, I expected this to parametrize into 2 tests and it doesn't seem to recognise it as being parameterized.
The text was updated successfully, but these errors were encountered: