fixture.py (13790:ed7f0a384c22) fixture.py (14141:b3ceff47211a)
1# Copyright (c) 2017 Mark D. Hill and David A. Wood
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 18 unchanged lines hidden (view full) ---

27# Authors: Sean Wilson
28
29import copy
30import traceback
31
32import helper
33import log
34
1# Copyright (c) 2017 Mark D. Hill and David A. Wood
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 18 unchanged lines hidden (view full) ---

27# Authors: Sean Wilson
28
29import copy
30import traceback
31
32import helper
33import log
34
35global_fixtures = []
36
37class SkipException(Exception):
38 def __init__(self, fixture, testitem):
39 self.fixture = fixture
40 self.testitem = testitem
41
42 self.msg = 'Fixture "%s" raised SkipException for "%s".' % (
43 fixture.name, testitem.name
44 )

--- 21 unchanged lines hidden (view full) ---

66 obj = super(Fixture, klass).__new__(klass, *args, **kwargs)
67 Fixture.collector.collect(obj)
68 return obj
69
70 def __init__(self, name=None, **kwargs):
71 if name is None:
72 name = self.__class__.__name__
73 self.name = name
35class SkipException(Exception):
36 def __init__(self, fixture, testitem):
37 self.fixture = fixture
38 self.testitem = testitem
39
40 self.msg = 'Fixture "%s" raised SkipException for "%s".' % (
41 fixture.name, testitem.name
42 )

--- 21 unchanged lines hidden (view full) ---

64 obj = super(Fixture, klass).__new__(klass, *args, **kwargs)
65 Fixture.collector.collect(obj)
66 return obj
67
68 def __init__(self, name=None, **kwargs):
69 if name is None:
70 name = self.__class__.__name__
71 self.name = name
72 self._is_global = False
74
75 def skip(self, testitem):
76 raise SkipException(self.name, testitem.metadata)
77
73
74 def skip(self, testitem):
75 raise SkipException(self.name, testitem.metadata)
76
78 def schedule_finalized(self, schedule):
79 '''
80 This method is called once the schedule of for tests is known.
81 To enable tests to use the same fixture defintion for each execution
82 fixtures must return a copy of themselves in this method.
83
84 :returns: a copy of this fixture which will be setup/torndown
85 when the test item this object is tied to is about to execute.
86 '''
87 return self.copy()
88
89 def init(self, *args, **kwargs):
90 pass
91
92 def setup(self, testitem):
93 pass
94
95 def teardown(self, testitem):
96 pass
97
77 def init(self, *args, **kwargs):
78 pass
79
80 def setup(self, testitem):
81 pass
82
83 def teardown(self, testitem):
84 pass
85
98 def copy(self):
99 return copy.deepcopy(self)
100
101 def skip_cleanup(self):
102 '''
103 If this method is called, then we should make sure that nothing is
104 done when the teardown() function is called.
105 '''
106 pass
107
86 def skip_cleanup(self):
87 '''
88 If this method is called, then we should make sure that nothing is
89 done when the teardown() function is called.
90 '''
91 pass
92
93 def set_global(self):
94 self._is_global = True
108
95
109def globalfixture(fixture):
110 '''
111 Store the given fixture as a global fixture. Its setup() method
112 will be called before the first test is executed.
113 '''
114 global_fixtures.append(fixture)
115 return fixture
96 def is_global(self):
97 return self._is_global