Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021
  1. def dataProvider(fn_data_provider):
  2. """
  3. Data provider decorator, allows another callable to provide the data for the test.
  4. This is a nice feature from PHPUnit which is very useful.
  5. Implementation basd on http://melp.nl/2011/02/phpunit-style-dataprovider-in-python-unit-test/#more-525
  6. """
  7. def test_decorator(test_method):
  8. def execute_test_method_with_each_data_set(self):
  9. for data in fn_data_provider():
  10. if len(data) == 2 and isinstance(data[0], tuple) and isinstance(data[1], dict):
  11. # Both args and kwargs being provided
  12. args, kwargs = data[:]
  13. else:
  14. args, kwargs = data, {}
  15. try:
  16. test_method(self, *args, **kwargs)
  17. except AssertionError, e:
  18. self.fail("%s (Provided data: %s, %s)" % (e, args, kwargs))
  19. return execute_test_method_with_each_data_set
  20. return test_decorator