Test Failed
Pull Request — master (#3204)
by W
03:58
created

BaseActionTest.tearDownClass()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
import logging
17
import six
18
import unittest
19
20
21
class BaseActionTest(unittest.TestCase):
22
23
    @classmethod
24
    def setUpClass(cls):
25
        super(BaseActionTest, cls).setUpClass()
26
        cls.log_stream = six.StringIO()
27
        cls.log_format = '%(asctime)s %(levelname)s [-] %(message)s'
28
        cls.log_formatter = logging.Formatter(cls.log_format)
29
        cls.logger = logging.getLogger()
30
        cls.logger.setLevel(logging.DEBUG)
31
32
    @classmethod
33
    def tearDownClass(cls):
34
        cls.log_stream.close()
35
        super(BaseActionTest, cls).tearDownClass()
36
37
    def setUp(self):
38
        super(BaseActionTest, self).setUp()
39
        self.log_handler = logging.StreamHandler(self.log_stream)
40
        self.log_handler.setFormatter(self.log_formatter)
41
        self.log_handler.flush()
42
        self.logger.addHandler(self.log_handler)
43
44
    def tearDown(self):
45
        self.log_handler.close()
46
        self.logger.removeHandler(self.log_handler)
47
        super(BaseActionTest, self).tearDown()
48