Kombinieren Sie Unittest mit ddt.idataPython

Python-Programme
Anonymous
 Kombinieren Sie Unittest mit ddt.idata

Post by Anonymous »

Meine Tests verwenden einen @idata Dekorateur aus dem DDT -Paket. Ich möchte nur eine der dekorierten Testmethoden durchführen (

Code: Select all

test01_...
) in der Testklasse, nicht alle von ihnen. Es steht in Konflikt mit einer unittesten Notation, Tests auszuwählen: No -Ansatz, die dort aufgeführt sind, ohne TestClass anzugeben. Wie kann ich es erreichen? < /P>
Beispiel: < /p>

Code: Select all

#!/usr/bin/env python3

import unittest
import sys

from ddt import idata, ddt

test_data_01 = [
["example1", "example2"],
["example3", "example4"],
]

test_data_02 = [
["other1", "other2"],
]

@ddt
class ExampleTest(unittest.TestCase):

@idata(test_data_01)
def test_01(self, params):
print(params)

@idata(test_data_02)
def test_02(self, params):
print(params)

if __name__ == "__main__":
sys.stdout = sys.__stdout__
unittest.main()
< /code>
Dies funktioniert: < /p>
bash-3.2$ ./ddt_problem.py
['example1', 'example2']
.['example3', 'example4']
.['other1', 'other2']
.
----------------------------------------------------------------------
Ran 3 tests in 0.005s

OK
< /code>
Die typische Ausführung eines bestimmten Tests ist nicht: < /p>
bash-3.2$ /usr/bin/python3 ./ddt_problem.py ExampleTest.test_02
Traceback (most recent call last):
File "./ddt_problem.py", line 31, in 
unittest.main()
File "/usr/python3.6/lib/python3.6/unittest.py", line 1296, in __init__
self.parseArgs(argv)
File "/usr/python3.6/lib/python3.6/unittest.py", line 1349, in parseArgs
self.createTests()
File "/usr/python3.6/lib/python3.6/unittest.py", line 1353, in createTests
self.module)
File "/usr/python3.6/lib/python3.6/unittest.py", line 659, in loadTestsFromNames
testCase = self.loadTestsFromName(name, module)
File "/usr/python3.6/lib/python3.6/unittest.py", line 626, in loadTestsFromName
obj = getattr(obj, part)
AttributeError: type object 'ExampleTest' has no attribute 'test_02'

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post