Skip to content

Commit dec6862

Browse files
committed
Make GLOBAL_TEST_FIXTURES support Python functions as fixtures
- Legacy-Id: 6906
1 parent e32d346 commit dec6862

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

ietf/utils/test_runner.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3333
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

35-
import socket, re, os, time
35+
import socket, re, os, time, importlib
3636

3737
from django.conf import settings
3838
from django.template import TemplateDoesNotExist
@@ -57,8 +57,18 @@ def safe_create_1(self, verbosity, *args, **kwargs):
5757
print " Using OPTIONS: %s" % settings.DATABASES["default"]["OPTIONS"]
5858
test_database_name = old_create(self, 0, *args, **kwargs)
5959
if settings.GLOBAL_TEST_FIXTURES:
60-
print " Loading global test fixtures: %s" % ", ".join(settings.GLOBAL_TEST_FIXTURES)
61-
call_command('loaddata', *settings.GLOBAL_TEST_FIXTURES, verbosity=0, commit=False, database="default")
60+
print " Loading global test fixtures: %s" % ", ".join(settings.GLOBAL_TEST_FIXTURES)
61+
loadable = [f for f in settings.GLOBAL_TEST_FIXTURES if "." not in f]
62+
call_command('loaddata', *loadable, verbosity=0, commit=False, database="default")
63+
64+
for f in settings.GLOBAL_TEST_FIXTURES:
65+
if f not in loadable:
66+
# try to execute the fixture
67+
components = f.split(".")
68+
module = importlib.import_module(".".join(components[:-1]))
69+
fn = getattr(module, components[-1])
70+
fn()
71+
6272
return test_database_name
6373

6474
def safe_destroy_0_1(*args, **kwargs):

0 commit comments

Comments
 (0)