Open esterfarbstein opened 3 years ago
The get_tests
function is not called from the test itself per se. It is called by the loader to attach the parametrization to tests, and in your example it should be called only once per test (twice in this particular snippet). Is this not what happens?
@vmalloc , get_tests
is called once per test - that's included tests that I don't want them to run now.
If I will have 10 tests in this file - so the get_tests
function will be called 10 times - although I want it to be called just one time for the specific test that I called.
(Also, if I use global variables in the get_tests
function they will be override and will get their value from the last test in this file)
So, can I run this function just for the function that I called?
Thanks, Ester
Well, this is kind of a chicken-and-egg problem, isn't it? The exact value of the parametrization is dependent on get_tests
, and this means that whether or not -k a
will apply to the test or not is dependent on the evaluation of get_tests()
... So I don't see a way around it without modifying the code... What exactly do you want get_tests
to do here?
I don't really understand why we need to call parametrization of test_b if we just run test_a (-k "a")? I expect that just the test_a parametrization will happen Is the parametrization happens before we are looking for the specific tests with the requested tag?
-k
is substring search, so if you have a test that is parametrized with x=bla
, and you pass -k bla
, the test will be run. If not, it won't.
@vmalloc thank you for your quick and full answers.
I tried to use now the tag search option -k tag:a
and also now it calls the parameterize of test_b function although this function's tag not contains "a".
Why do we need to call test_b parameterize?
Actually it's not Slash that calls it - it is you:
@slash.parametrize('test_data', get_tests())
@slash.tag('a')
def test_a(test_data):
pass
is equivalent to writing
_temp_var = get_tests()
@slash.parametrize('test_data', _temp_var))
@slash.tag('a')
def test_a(test_data):
pass
As you can see it is called by the module being loaded.... There is no actual way in Python to load your test file without going through all of these calls...
Hi, I have some tests in the same file. For each test the parametrize decorator calls a function. for example:
When I run just one test, for example -k "a" : the get_tests() function have been called twice or even more - when I add more tests with the same behavior. How can I change this behavior that the get_test will be called just one time from the specific test that I want to run?
Thanks, Ester