You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say that I need to test some function, which explicitly checks the type of its input, and I have no control over this behavior. Also, let's say, that I need a fixture for such test:
So far, so good - everything works as expected and I get <class 'int'> in the output.
BUT!
If I change this fixture to autouse=True (because e.g. I have a lots of tests like the one above and I just don't want to repeat the same declaration over and over):
...then everything breaks with AssertionError: sorry, integers only! (well, obviously), because my_fixture is now <class 'function'>.
Assuming that this is a feature, not a bug, my question is: what is the "canonical" way of handling such situations?
EDIT: actually, I've just realized that this type assertion here is irrelevant - this autouse=True case will just "explode" on return x + 1 for exactly the same reason.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say that I need to test some function, which explicitly checks the type of its input, and I have no control over this behavior. Also, let's say, that I need a fixture for such test:
So far, so good - everything works as expected and I get
<class 'int'>
in the output.BUT!
If I change this fixture to
autouse=True
(because e.g. I have a lots of tests like the one above and I just don't want to repeat the same declaration over and over):...then everything breaks with
AssertionError: sorry, integers only!
(well, obviously), becausemy_fixture
is now<class 'function'>
.Assuming that this is a feature, not a bug, my question is: what is the "canonical" way of handling such situations?
EDIT: actually, I've just realized that this type assertion here is irrelevant - this
autouse=True
case will just "explode" onreturn x + 1
for exactly the same reason.Beta Was this translation helpful? Give feedback.
All reactions