|
3 | 3 | import time
|
4 | 4 |
|
5 | 5 | import pytest
|
| 6 | +import six |
6 | 7 |
|
7 | 8 | from .test_data_tools.data_tool import (
|
8 | 9 | generate_orient_integration_data, generate_orient_snapshot_data, generate_sql_integration_data,
|
@@ -61,13 +62,30 @@ def integration_graph_client(request, init_integration_graph_client):
|
61 | 62 | request.cls.graph_client = init_integration_graph_client
|
62 | 63 |
|
63 | 64 |
|
64 |
| -@pytest.fixture(scope="class") |
| 65 | +@pytest.fixture(scope='class') |
65 | 66 | def sql_integration_data(request):
|
66 | 67 | """Generate integration data for SQL backends."""
|
| 68 | + # initialize each SQL backend, and open a transaction on each one. |
67 | 69 | sql_test_backends = init_sql_integration_test_backends()
|
| 70 | + # write fixture test data within the transaction |
68 | 71 | generate_sql_integration_data(sql_test_backends)
|
| 72 | + # make sql backends accessible within the test class |
69 | 73 | request.cls.sql_test_backends = sql_test_backends
|
70 | 74 | # yield the fixture to allow testing class to run
|
71 | 75 | yield
|
72 |
| - # tear down the fixture after the testing class runs all tests. |
| 76 | + # tear down the fixture after the testing class runs all tests |
| 77 | + # including rolling back transaction to ensure all fixture data removed. |
73 | 78 | tear_down_integration_test_backends(sql_test_backends)
|
| 79 | + |
| 80 | + |
| 81 | +@pytest.fixture(scope='function') |
| 82 | +def sql_integration_test(request): |
| 83 | + """Open nested transaction before every test function, and rollback transaction afterwards.""" |
| 84 | + sql_test_backends = request.cls.sql_test_backends |
| 85 | + test_transactions = [] |
| 86 | + for sql_test_backend in six.itervalues(sql_test_backends): |
| 87 | + transaction = sql_test_backend.connection.begin_nested() |
| 88 | + test_transactions.append(transaction) |
| 89 | + yield |
| 90 | + for transaction in test_transactions: |
| 91 | + transaction.rollback() |
0 commit comments