-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatadriventest.py
63 lines (46 loc) · 1.7 KB
/
datadriventest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from nose.tools import istest
from nose.tools import assert_not_equal
from nose.tools import assert_true
from snot import Requirements
__author__ = 'Jason Corbett'
setup_module_called = False
def setup_module():
global setup_module_called
setup_module_called = True
@istest
def test_data_driven():
test_data = [
['Test1', 'arg2', Requirements(['one', 'two'])],
['Test2', 'arg2', 'foo'],
['Test3', 'arg2', 'bar'],
]
for data in test_data:
yield ddt, data[0], data[1], data[2]
def ddt(test_name, argument, requirements):
"""Test: {0}"""
assert_true(setup_module_called, "Setup module was not called")
assert_not_equal(test_name, argument, "The test name \"{}\" should not equal the argument \"{}\"".format(test_name,
argument))
class DataDrivenTestClass(object):
classSetupCalled = False
@classmethod
def setupClass(cls):
cls.classSetupCalled = True
def __init__(self):
self.setupCalled = False
def setUp(self):
self.setupCalled = True
@istest
def test_data_driven_inside_class(self):
test_data = [
['Test1', 'Test1'],
['Test1', 'Test2'],
['Test1', 'Test3']
]
for data in test_data:
yield self.verify_not_equals, data[0], data[1]
def verify_not_equals(self, first, second):
"""Verify {0} does not equal {1}"""
assert_true(self.setupCalled, "Setup was not called")
assert_true(setup_module_called, "Module setup was not called")
assert_true(self.classSetupCalled, "Class setup was not called")