-
Notifications
You must be signed in to change notification settings - Fork 40
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
'parametrize_with_cases' does not work with 'cases=AUTO2' param #140
Comments
Thanks @romanponomaryov for reporting this ! Indeed it seems weird. I tried to reproduce the error but could not, unfortunately :( Can you try to do this in debug mode, and to put a breakpoint at the beginning of your Also concerning the string variant, I am not against it. However consider that users already import parametrize_with_cases so adding another import is just as quick as <alt+enter> in pycharm. But of course we should not take IDE into account when writing libs, so I agree with you. |
I don't think there's a problem with my cases file, as
I created 'test_experiment.py' which has only one function from my initial file with tests ('test_<name>.py') |
It turns out that in my 'test_<name>.py' I had another test function: @parametrize_with_cases('my_var_2')
def test_my_func_2(my_var_2):
... And this was causing the issue. When I updated 'cases=AUTO2' for this function as well - the issue went away. |
One more note concerning the string variant (cases=AUTO2 vs cases="AUTO2"). It's not a problem to make an import of AUTO2, but to figure out that I needed to make it in order to use it as a value for the parameter took some time and seemed counterintuitive. Maybe it's just me, though. |
Thanks for the detailed feedback @romanponomaryov ! Glad you could find a way to fix this I'll leave this ticket open for later times (I will soon be inactive for family reasons for a couple of weeks), so that I can try to imagine a way to improve the user experience for the future. Maybe one way would be to automate the search completely (merging AUTO2 into AUTO so that both names are searched for in a row ?). An alternative could be to explicitly declare the AUTO2 mode in the module somewhere (in a global variable or in a method called at the top of the module)... If you have other ideas do not hesitate to post them here ! |
Ideally, three cases can be satisfied here:
How to do this though...
|
Thanks for the proposal @romanponomaryov ! I very much like your |
New decorator is not needed per se for case 3. Same thing can be achieved e.g. via having same parameters "cases_file_prefix" and "cases_file_suffix" in @parametrize_with_cases. And maybe @parametrize_with_cases can be made to work with test classes. |
Hi @romanponomaryov , for now I have implemented a basic fusion of both naming convention: now This will be released in 3.1.0. Feel free to open a new ticket referencing this if there is any other of your suggestion you would like to pursue. |
Hi, Sylvain!
The problem is as follows:
I have a file 'test_<name>.py' with test functions. In the same directory I also have a file with cases, which is called 'cases_<name>.py'.
If I use in 'test_<name>.py':
then when I run my tests I get an error:
Mind the "unable to import AUTO" - it's supposed to be "AUTO2" as I understand..
If I use 'test_<name>_cases.py' as a name for the file with cases and "cases=AUTO" or do not mention the "cases" param - all works fine.
If I delete or rename the file with cases and run the tests with "cases=AUTO2" - I get:
So - this time AUTO2 is mentioned correctly and the name of the file pytest is trying to find is as expected.
Could you please look into this?
On another note, it seems weird that I have to import AUTO2 from pytest_cases.common_others to be able to use it in 'cases' parameter.
It would be much more intuitive to submit it as a string:
@parametrize_with_cases('my_var', cases='AUTO2')
. Or maybe I'm doing something wrong here?I'm using pytest 6.0.1 and pytest-cases 2.2.5
Thanks in advance for your answer
The text was updated successfully, but these errors were encountered: