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
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
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
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
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
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