You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importunittesttry:
importnumpy# pylint: disable=unused-importHAS_NUMPY=TrueexceptImportError:
HAS_NUMPY=False@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.")classBrainNumpyCoreFromNumericTest(unittest.TestCase):
numpy_functions= (("sum", "[1, 2]"),)
deftest_numpy_function_calls_inferred_as_ndarray(self):
""" Test that calls to numpy functions are inferred as numpy.ndarray """licit_array_types= (".ndarray",)
forfunc_inself.numpy_functions:
withself.subTest(typ=func_):
inferred_values=list(self._inferred_numpy_func_call(*func_))
self.assertEqual(
len(inferred_values),
1,
msg=f"Too much inferred value for {func_[0]:s}",
)
self.assertIn(
inferred_values[-1].pytype(),
licit_array_types,
msg=f"Illicit type for {func_[0]:s} ({inferred_values[-1].pytype()})",
)
Give the following result:
importpytesttry:
importnumpy# pylint: disable=unused-importHAS_NUMPY=TrueexceptImportError:
HAS_NUMPY=Falsefromastroidimportbuilder@pytest.mark.skipif(notHAS_NUMPY, "This test requires the numpy library.")classTestBrainNumpyCoreFromNumeric:
""" Test the numpy core fromnumeric brain module """numpy_functions= (("sum", "[1, 2]"),)
deftest_numpy_function_calls_inferred_as_ndarray(self):
""" Test that calls to numpy functions are inferred as numpy.ndarray """licit_array_types= (".ndarray",)
forfunc_inself.numpy_functions:
withself.subTest(typ=func_):
inferred_values=list(self._inferred_numpy_func_call(*func_))
assert (
len(inferred_values) ==1
), f"Too much inferred value for {func_[0]:s}"assert (
inferred_values[-1].pytype() inlicit_array_types
), f"Illicit type for {func_[0]:s} ({inferred_values[-1].pytype()})"
I think self.subTest(typ=func_): should be converted to a pytest.parametrize. Reference documentation
Context : I'm trying to migrate astroid's test to pytest style, there's 36 subtests 😄
The text was updated successfully, but these errors were encountered:
i'll admit, this will actually be very hard to do, because it's not a simple syntax replacement. as you mentioned, one can use pytest.mark.parametrize, or there's even a pytest-subtests package!
after some thought, if we were to use pytest-subtests, this would be a simpler find-and-replace. so maybe we can wait and see if pytest-dev/pytest-subtests#71 gets merged
we'd maybe still want a feature flag to opt-in or opt-out of this behavior, but we can come to that later
Hello, thank you for creating this tool !
The following code:
Give the following result:
I think
self.subTest(typ=func_):
should be converted to apytest.parametrize
.Reference documentation
Context : I'm trying to migrate astroid's test to pytest style, there's 36 subtests 😄
The text was updated successfully, but these errors were encountered: