blob: ad9ce466c8034f0da35a1dc7a5bf24061c948650 [file] [log] [blame]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +03001# Copyright 2016 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from __future__ import division
16import time
17
18import pytest
19
20from tcp_tests import logger
21from tcp_tests.helpers import log_step
22from tcp_tests.helpers import utils
23
24
25LOG = logger.logger
26
27
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030028@pytest.hookimpl(tryfirst=True, hookwrapper=True)
29def pytest_runtest_makereport(item, call):
30 outcome = yield
31 rep = outcome.get_result()
32 setattr(item, "rep_" + rep.when, rep)
33
34
35def pytest_runtest_setup(item):
36 if item.cls is not None:
37 item.cls._current_test = item.function
38 item._start_time = time.time()
39 head = "<" * 5 + "#" * 30 + "[ {} ]" + "#" * 30 + ">" * 5
40 head = head.format(item.function.__name__)
41 start_step = "\n{head}".format(head=head)
42 LOG.info(start_step)
43
44
45def pytest_runtest_teardown(item):
46 step_name = item.function.__name__
47 if hasattr(item, '_start_time'):
48 spent_time = time.time() - item._start_time
49 else:
50 spent_time = 0
51 minutes = spent_time // 60
52 seconds = int(round(spent_time)) % 60
53 finish_step = "FINISH {} TEST. TOOK {} min {} sec".format(
54 step_name, minutes, seconds
55 )
56 foot = "\n" + "<" * 5 + "#" * 30 + "[ {} ]" + "#" * 30 + ">" * 5
57 foot = foot.format(finish_step)
58 LOG.info(foot)
59
60
61@pytest.fixture(scope='function')
62def show_step(request):
63 def _show_step(step_number):
64 return log_step.log_step(request.function, step_number)
65 return _show_step
Dennis Dmitriev474e3f72016-10-21 16:46:09 +030066
67@pytest.fixture(scope='function')
68def steps(request):
69 steps_mark = request.keywords.get('steps', None)
70 steps = steps_mark.args[0]
71 return steps