Changeset 335271e in sasmodels for conftest.py
- Timestamp:
- Jan 31, 2018 2:59:52 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 0e7611b
- Parents:
- f354e46
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
conftest.py
r6dba2f0 r335271e 20 20 import pytest 21 21 from _pytest.unittest import TestCaseFunction 22 from _pytest.compat import is_generator 23 24 def pytest_pycollect_makeitem(collector, name, obj): 25 """ 26 Convert test generator into list of function tests so that pytest doesn't 27 complain about deprecated yield tests. 28 29 Note that unlike nose, the tests are generated and saved instead of run 30 immediately. This means that any dynamic context, such as a for-loop 31 variable, must be captured by wrapping the yield result in a function call. 32 33 For example:: 34 35 for value in 1, 2, 3: 36 for test in test_cases: 37 yield test, value 38 39 will need to be changed to:: 40 41 def build_test(test, value): 42 return test, value 43 for value in 1, 2, 3: 44 for test in test_cases: 45 yield build_test(test, value) 46 47 This allows the context (test and value) to be captured by lexical closure 48 in build_test. See https://stackoverflow.com/a/233835/6195051. 49 """ 50 if collector.istestfunction(obj, name) and is_generator(obj): 51 tests = [pytest.Function(name, parent=collector, args=yielded[1:], callobj=yielded[0]) 52 for yielded in obj()] 53 return tests 54 22 55 23 56 USE_DOCSTRING_AS_DESCRIPTION = True
Note: See TracChangeset
for help on using the changeset viewer.