Opened 2 years ago

Closed 2 years ago

#33633 closed Cleanup/optimization (fixed)

Some test_utils tests fail on databases that don't support transactions.

Reported by: Xiang Zhang Owned by: Xiang Zhang
Component: Core (Other) Version: 4.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Xiang Zhang)

FAIL: test_reset_sequences (test_utils.test_testcase.TestTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/zhangyangyu/repos/django-tidb/django_tests_dir/django/tests/test_utils/test_testcase.py", line 47, in test_reset_sequences
    old_reset_sequences = self.reset_sequences
  File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 126, in __exit__
    next(self.gen)
  File "/Users/zhangyangyu/repos/django-tidb/django_tests_dir/django/django/test/testcases.py", line 807, in _assert_raises_or_warns_cm
    yield cm
AssertionError: TypeError not raised
FAIL: test_execute_tree (test_utils.tests.CaptureOnCommitCallbacksTests)
A visualisation of the callback tree tested. Each node is expected to
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/zhangyangyu/repos/django-tidb/django_tests_dir/django/tests/test_utils/tests.py", line 1657, in test_execute_tree
    self.assertEqual(callbacks, [branch_1, branch_2, leaf_3, leaf_1, leaf_2])
AssertionError: Lists differ: [] != [<function CaptureOnCommitCallbacksTests.t[412 chars]ee0>]

Second list contains 5 additional elements.
First extra element 0:
<function CaptureOnCommitCallbacksTests.test_execute_tree.<locals>.branch_1 at 0x107c52430>

- []
+ [<function CaptureOnCommitCallbacksTests.test_execute_tree.<locals>.branch_1 at 0x107c52430>,
+  <function CaptureOnCommitCallbacksTests.test_execute_tree.<locals>.branch_2 at 0x107c52040>,
+  <function CaptureOnCommitCallbacksTests.test_execute_tree.<locals>.leaf_3 at 0x107c52dc0>,
+  <function CaptureOnCommitCallbacksTests.test_execute_tree.<locals>.leaf_1 at 0x107e17310>,
+  <function CaptureOnCommitCallbacksTests.test_execute_tree.<locals>.leaf_2 at 0x107c52ee0>]
FAIL: test_execute_recursive (test_utils.tests.CaptureOnCommitCallbacksTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/zhangyangyu/repos/django-tidb/django_tests_dir/django/tests/test_utils/tests.py", line 1604, in test_execute_recursive
    self.assertEqual(len(callbacks), 2)
AssertionError: 0 != 2

test_reset_sequences/test_execute_tree/test_execute_recursive fail with above error if testing against backends not supporting transactions, like MySQL MyIASM engine.

Change History (7)

comment:1 by Xiang Zhang, 2 years ago

Description: modified (diff)
Summary: test_reset_sequences fails for backends not supporting transactionstest_reset_sequences/test_execute_tree/test_execute_recursive fail for backends not supporting transactions

comment:2 by Mariusz Felisiak, 2 years ago

Component: Testing frameworkCore (Other)
Summary: test_reset_sequences/test_execute_tree/test_execute_recursive fail for backends not supporting transactionsSome test_utils tests fail on databases that don't support transactions.
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Thanks for the report. I was able to reproduce even more failures:

ERROR: test_failure_in_setUpTestData_should_rollback_transaction (test_utils.tests.TestBadSetUpTestData)
FAIL: test_reset_sequences (test_utils.test_testcase.TestTestCase)
FAIL: test_class_attribute_identity (test_utils.test_testcase.TestDataTests)
FAIL: test_execute (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_execute_recursive (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_execute_tree (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_no_arguments (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_pre_callback (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_using (test_utils.tests.CaptureOnCommitCallbacksTests)

CaptureOnCommitCallbacksTests should be skipped on databases that don't support transactions, i.e. decorated with @skipUnlessDBFeature("supports_transactions"). I didn't check other failures. Would you like to prepare a patch?

in reply to:  2 comment:3 by Xiang Zhang, 2 years ago

Replying to Mariusz Felisiak:

Thanks for the report. I was able to reproduce even more failures:

ERROR: test_failure_in_setUpTestData_should_rollback_transaction (test_utils.tests.TestBadSetUpTestData)
FAIL: test_reset_sequences (test_utils.test_testcase.TestTestCase)
FAIL: test_class_attribute_identity (test_utils.test_testcase.TestDataTests)
FAIL: test_execute (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_execute_recursive (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_execute_tree (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_no_arguments (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_pre_callback (test_utils.tests.CaptureOnCommitCallbacksTests)
FAIL: test_using (test_utils.tests.CaptureOnCommitCallbacksTests)

CaptureOnCommitCallbacksTests should be skipped on databases that don't support transactions, i.e. decorated with @skipUnlessDBFeature("supports_transactions"). I didn't check other failures. Would you like to prepare a patch?

Yes. I also find more tests fail but for me the three are most important. Let me submit a fix.

comment:4 by Mariusz Felisiak, 2 years ago

Owner: changed from nobody to Xiang Zhang
Status: newassigned

Yes. I also find more tests fail but for me the three are most important. Let me submit a fix.

Great, thanks.

comment:6 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 1bb9bd97:

Fixed #33633 -- Skipped some test_utils tests on databases that don't support transactions.

Note: See TracTickets for help on using tickets.
Back to Top