Skip to content

Commit fa9624c

Browse files
authored
make dtype testing more concise (#15)
* make dtype testing more concise Instead of instantiating the tests for all devices and use the `@onlyCPU` decorator everywhere, used the `only_for` keyword when instantiating. With that the meta tests are not generated in the first place and do not need to be considered for the number of skipped tests. * cleanup
1 parent 0279a23 commit fa9624c

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

tests/assets/test_dtype.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
from torch.testing._internal.common_device_type import (
55
dtypes,
66
instantiate_device_type_tests,
7-
onlyCPU,
87
)
98
from torch.testing._internal.common_utils import TestCase
109

1110

1211
class TestFoo(TestCase):
13-
@onlyCPU
1412
@dtypes(torch.float16, torch.int32)
1513
# fails for float16, passes for int32
1614
def test_bar(self, device, dtype):
1715
assert dtype == torch.int32
1816

1917
# passes for float16, skips for int32
20-
@onlyCPU
2118
@dtypes(torch.float16, torch.int32)
2219
def test_baz(self, device, dtype):
2320
if dtype == torch.int32:
@@ -26,18 +23,16 @@ def test_baz(self, device, dtype):
2623
assert True
2724

2825

29-
instantiate_device_type_tests(TestFoo, globals())
26+
instantiate_device_type_tests(TestFoo, globals(), only_for="cpu")
3027

3128

3229
class TestSpam(TestCase):
33-
@onlyCPU
3430
def test_ham(self, device):
3531
assert True
3632

37-
@onlyCPU
3833
@dtypes(torch.float16)
3934
def test_eggs(self, device, dtype):
4035
assert False
4136

4237

43-
instantiate_device_type_tests(TestSpam, globals())
38+
instantiate_device_type_tests(TestSpam, globals(), only_for="cpu")

tests/test_plugin.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -97,83 +97,77 @@ def test_device(testdir, file, cmds, outcomes):
9797
new_cmds=(),
9898
legacy_cmds=(),
9999
passed=3,
100-
skipped=7,
100+
skipped=1,
101101
failed=2,
102102
),
103103
Config(
104104
"1testcase1-*test-*dtype",
105105
new_cmds="::TestFoo",
106106
legacy_cmds=("-k", "TestFoo"),
107107
passed=2,
108-
skipped=5,
108+
skipped=1,
109109
failed=1,
110110
),
111111
Config(
112-
"1testcase2-*test-*device",
112+
"1testcase2-*test-*dtype",
113113
new_cmds="::TestSpam",
114114
legacy_cmds=("-k", "TestSpam"),
115115
passed=1,
116-
skipped=2,
117116
failed=1,
118117
),
119118
Config(
120119
"*testcase-*test-1dtype1",
121120
new_cmds=("-k", "float16"),
122121
legacy_cmds=("-k", "float16"),
123122
passed=1,
124-
skipped=3,
125123
failed=2,
126124
),
127125
Config(
128126
"*testcase-*test-1dtype2",
129127
new_cmds=("-k", "int32"),
130128
legacy_cmds=("-k", "int32"),
131129
passed=1,
132-
skipped=3,
130+
skipped=1,
133131
),
134132
Config(
135133
"1testcase-*test-1dtype1",
136134
new_cmds=("::TestFoo", "-k", "float16"),
137135
legacy_cmds=("-k", "TestFoo and float16"),
138136
passed=1,
139137
failed=1,
140-
skipped=2,
141138
),
142139
Config(
143140
"1testcase-*test-1dtype2",
144141
new_cmds=("::TestFoo", "-k", "int32"),
145142
legacy_cmds=("-k", "TestFoo and int32"),
146143
passed=1,
147-
skipped=3,
144+
skipped=1,
148145
),
149146
Config(
150147
"1testcase-1test1-*dtype",
151148
new_cmds="::TestFoo::test_bar",
152149
legacy_cmds=("-k", "TestFoo and test_bar"),
153150
passed=1,
154-
skipped=2,
155151
failed=1,
156152
),
157153
Config(
158154
"1testcase-1test2-*dtype",
159155
new_cmds="::TestFoo::test_baz",
160156
legacy_cmds=("-k", "TestFoo and test_baz"),
161157
passed=1,
162-
skipped=3,
158+
skipped=1,
163159
),
164160
Config(
165161
"1testcase-1test-1dtype1",
166162
new_cmds=("::TestFoo::test_bar", "-k", "float16"),
167163
legacy_cmds=("-k", "TestFoo and test_bar and float16"),
168-
skipped=1,
169164
failed=1,
170165
),
171166
Config(
172167
"1testcase-1test-1dtype2",
173168
new_cmds=("::TestFoo::test_bar", "-k", "int32"),
174169
legacy_cmds=("-k", "TestFoo and test_bar and int32"),
175170
passed=1,
176-
skipped=1,
177171
),
178172
)
179173
def test_dtype(testdir, file, cmds, outcomes):

0 commit comments

Comments
 (0)