wolever / parameterized

Parameterized testing with any Python test framework
Other
833 stars 105 forks source link

Lazy creation parameterized_class attributes #139

Closed anudeepsamaiya closed 1 year ago

anudeepsamaiya commented 2 years ago

Is it possible to provide the attributes to parametrize_class decorators lazily, such that the test factory should run only when the particular test class is being executed?

@parameterized_class(
    [{"address_object": x} for x in AddressFactory.create_batch(20)]
)
class SomeTests:
     pass

The @parametrize decorator supports taking a function as an argument, but @parametrized_class decorator does not support functions or generators.

wolever commented 1 year ago

It would be possible (PR very welcome!) to update parameterized_class to accept a callable, but unfortunately I'm not sure whether it would be possible to lazily evaluate that callable when the class under test is executed. Specifically, test runners typically collect all the tests to be run first, then execute them, and I'm not sure how this lazy evaluation would interact with that semantic.

Please feel free to re-open this issue if you can think of a way to make this work!