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
Enumeration of the cases for a parameterized test method in an absl.testing.parameterized.TestCase is eager: it happens at the point where the class is defined.
Under normal circumstances, this is before googletest.main() has been called, meaning that the sequence of cases cannot depend on the values of flags defined by absl.flags (or, indeed, on anything that is not meaningfully defined at the point that the TestCase class is created).
Thus, the following structure will not work:
fromabslimportflagsfromabsl.testingimportabsltestfromabsl.testingimportparameterizedMY_FLAG=flags.DEFINE_bool(...)
def_gen_cases():
return (xforxin ...) ifMY_FLAG.valueelse (yforyin ...) # But MY_FLAG won't have been set yetclassMyTest(parameterized.TestCase):
@parameterized.parameters(_gen_cases()):
deftest_my_condition(self, case):
...
if__name__=='__main__':
absltest.main()
Possible Fix
Either of two changes could fix this: making command-line flag parsing more eager, or making test case enumeration lazier. The latter seems simpler.
Each of parameterized.parameters(), parameterized.named_parameters(), parameterized.product() and so on could be widened to accept, in addition to the types that it currently accepts, a callable that returns one of those types. If it finds its argument is callable, it could defer enumeration of the cases until some point after command-line flags have been parsed.
Then the above snippet could be amended:
@parameterized.parameters(_gen_cases): # Note the generator is not called at this pointdeftest_my_condition(self, case):
The text was updated successfully, but these errors were encountered:
The idea of an implementation would be to make absl.testing.absltest.TestLoader aware of parameterized, and evaluate the parameterized test cases there. It needs to continue support test filtering, test order randomization.
Enumeration of the cases for a parameterized test method in an
absl.testing.parameterized.TestCase
is eager: it happens at the point where the class is defined.Under normal circumstances, this is before
googletest.main()
has been called, meaning that the sequence of cases cannot depend on the values of flags defined byabsl.flags
(or, indeed, on anything that is not meaningfully defined at the point that theTestCase
class is created).Thus, the following structure will not work:
Possible Fix
Either of two changes could fix this: making command-line flag parsing more eager, or making test case enumeration lazier. The latter seems simpler.
Each of
parameterized.parameters()
,parameterized.named_parameters()
,parameterized.product()
and so on could be widened to accept, in addition to the types that it currently accepts, acallable
that returns one of those types. If it finds its argument is callable, it could defer enumeration of the cases until some point after command-line flags have been parsed.Then the above snippet could be amended:
The text was updated successfully, but these errors were encountered: