Skip to content

[Test] Un-shadow duplicated test classes in test_lu_op.py and test_tensordot.py - #79767

Open
Anai-Guo wants to merge 1 commit into
PaddlePaddle:developfrom
Anai-Guo:fix/unshadow-duplicated-test-classes
Open

[Test] Un-shadow duplicated test classes in test_lu_op.py and test_tensordot.py#79767
Anai-Guo wants to merge 1 commit into
PaddlePaddle:developfrom
Anai-Guo:fix/unshadow-duplicated-test-classes

Conversation

@Anai-Guo

Copy link
Copy Markdown

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

Two unit-test files define a test class name twice at module level. Python keeps only the last binding, so unittest / pytest collect only the later class and the earlier case silently stops running.

1. test/legacy_test/test_lu_op.py

TestLUOp is defined at line 106 (# m < n, "case 1", x_shape = [3, 10, 12]) and again at line 387, where a zero-size case (x_shape = [2, 0, 12]) reuses the same name.

TestLUOp2TestLUOp5 still behave correctly — they subclass the first definition and captured the class object at class-creation time — but the m < n case itself is no longer collected, since the module attribute TestLUOp now points at the zero-size class.

Renamed the zero-size class to TestLUOpZeroSize, matching the TestLUAPIZeroSize naming already used in the same file. Both cases are then collected.

collected class before after
TestLUOp L387 zero-size [2, 0, 12] L106 m < n [3, 10, 12] (base of TestLUOp2TestLUOp5)
TestLUOpZeroSize (not collected) L387 zero-size [2, 0, 12]

Class count is unchanged (9 before, 9 after); one case is recovered.

2. test/legacy_test/test_tensordot.py

TestTensordotAPIZeroSize is defined at line 365 and again at line 385. The second definition is byte-identical to the first except that it adds set_dtypenp.float64 — which is exactly what TestTensordotAPIFloat64ZeroSize (line 380, a subclass of the first definition) already provides.

So the duplicate buys no extra coverage and costs the default float32 zero-size case: the collected TestTensordotAPIZeroSize runs float64, and float64 is then tested twice.

Removed the second definition. TestTensordotAPIZeroSize goes back to the base set_dtype (np.float32) and TestTensordotAPIFloat64ZeroSize continues to cover float64. No class defined after line 400 subclasses TestTensordotAPIZeroSize, so nothing else changes binding.

collected class before after
TestTensordotAPIZeroSize float64 (duplicate of TestTensordotAPIFloat64ZeroSize) float32 (base dtype)
TestTensordotAPIFloat64ZeroSize float64 float64 (unchanged)

Diff is +1 / −19, test-only.

是否引起精度变化

(Test-only. Two previously-uncollected cases start running again; no framework or kernel code is touched.)

🤖 Generated with Claude Code

…nsordot.py

Both files define a test class name twice at module level, so only the later
definition is collected and the earlier case never runs.

test_lu_op.py: the zero-size case added at the end of the file is also called
TestLUOp, which shadows the "case 1" m < n class it collides with. TestLUOp2-5
still subclass the original (they captured it at class-creation time), but the
[3, 10, 12] m < n case itself is no longer collected. Renamed the zero-size
class to TestLUOpZeroSize, matching TestLUAPIZeroSize in the same file.

test_tensordot.py: TestTensordotAPIZeroSize is defined twice. The second
definition is the first plus set_dtype -> float64, which is exactly what
TestTensordotAPIFloat64ZeroSize (a subclass of the first definition) already
provides. The duplicate therefore only costs the default float32 zero-size
case. Removed it; float64 stays covered by TestTensordotAPIFloat64ZeroSize.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@paddle-bot paddle-bot Bot added the contributor External developers label Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants