Как я понимаю, pytest должен предоставить информацию о параметре с unittest.TestCase.subtest()
, если тест не пройден.Итак, вот что-то, что напоминает мой код:
class TestStuff(unittest.TestCase):
def test_foo(self):
for i in range(0, 100):
with self.subTest(msg = "seed", i = i):
np.random.seed(i)
n = np.random.randint(0, 30)
self.assertGreaterEqual(28, n)
Этот курс не выполняется, и выводит следующее:
================================================================================================== test session starts ===================================================================================================
platform darwin -- Python 3.7.3, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
rootdir: /Users/foopackage
plugins: openfiles-0.3.2, arraydiff-0.3, doctestplus-0.3.0, remotedata-0.3.1
collected 7 items
foo.py ......F [100%]
======================================================================================================== FAILURES ========================================================================================================
________________________________________________________________________________________________ TestStuff.test_foo _________________________________________________________________________________________________
self = <foo.test_foo.TestStuff testMethod=test_foo>
def test_foo(self):
for i in range(0, 100):
with self.subTest(msg = "seed", i = i):
np.random.seed(i)
n = np.random.randint(0, 30)
> self.assertGreaterEqual(28, n)
E AssertionError: 28 not greater than or equal to 29
foo.py:135: AssertionError
=========================================================================================== 1 failed, 6 passed in 1.91 seconds ===========================================================================================
Как видите, нет сообщений о том, какое семя (значение я) не прошел тест.Я везде читал, что Pytest совместим с unittest, поэтому я не вижу проблемы здесь.Может кто-нибудь объяснить это?Thx