Skip to content

Commit

Permalink
Merge 952e8e0 into f251b5c
Browse files Browse the repository at this point in the history
  • Loading branch information
osherdp committed May 12, 2019
2 parents f251b5c + 952e8e0 commit 04b47f5
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 15 deletions.
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages


__version__ = "7.2.0"
__version__ = "7.2.1"

result_handlers = [
"db = rotest.core.result.handlers.db_handler:DBHandler",
Expand Down Expand Up @@ -47,6 +47,7 @@
'basicstruct',
'future',
'swaggapi>=0.6.5',
'cached_property',
],
extras_require={
"dev": [
Expand Down
8 changes: 4 additions & 4 deletions src/rotest/core/abstract_test.py
Expand Up @@ -16,6 +16,7 @@

from ipdbugger import debug
from attrdict import AttrDict
from cached_property import cached_property
from future.builtins import next, str, object
from future.utils import iteritems, itervalues

Expand Down Expand Up @@ -81,7 +82,6 @@ def __init__(self, methodName='test_method', indexer=count(), parent=None,
super(AbstractTest, self).__init__(methodName)

self.result = None
self.logger = None
self.is_main = True
self.config = config
self.parent = parent
Expand Down Expand Up @@ -250,10 +250,10 @@ def _get_parents_count(self):

return self.parent.parents_count + 1

def create_logger(self):
@cached_property
def logger(self):
"""Create logger instance for the test."""
if self.logger is None:
self.logger = get_test_logger(get_tree_path(self), self.work_dir)
return get_test_logger(get_tree_path(self), self.work_dir)

def start(self):
"""Update the data that the test started."""
Expand Down
1 change: 0 additions & 1 deletion src/rotest/core/case.py
Expand Up @@ -158,7 +158,6 @@ def run(self, result=None):
# method signature, but the Rotest test case does not support it.
self.assertIsNotNone(result, 'TestCase must run inside a TestSuite')
self.result = result
self.create_logger()

# === Decorate the setUp, test and tearDown methods. ===
setup_method = getattr(self, self.SETUP_METHOD_NAME)
Expand Down
6 changes: 0 additions & 6 deletions src/rotest/core/flow.py
Expand Up @@ -136,12 +136,6 @@ def __iter__(self):
def addTest(self, test_item):
self._tests.append(test_item)

def create_logger(self):
"""Create logger instances for the test and its components."""
super(TestFlow, self).create_logger()
for block in self._tests:
block.create_logger()

def validate_inputs(self, extra_inputs=[]):
"""Validate that all the required inputs of the blocks were passed.
Expand Down
1 change: 0 additions & 1 deletion src/rotest/core/flow_component.py
Expand Up @@ -328,7 +328,6 @@ def run(self, result=None):
result (rotest.core.result.result.Result): test result information.
"""
self.result = result
self.create_logger()

# === Decorate the setUp and tearDown methods ===
setup_method = getattr(self, self.SETUP_METHOD_NAME)
Expand Down
Expand Up @@ -179,8 +179,6 @@ def _handle_start_message(self, test, message):
message (StartTest): worker message object.
"""
# Since the logger is only created in the worker, we create it here
test.create_logger()

self.result.startTest(test)
if test.is_main:
self.runner.update_worker(worker_pid=message.msg_id, test=test)
Expand Down
23 changes: 23 additions & 0 deletions tests/core/test_flow.py
Expand Up @@ -125,6 +125,29 @@ def test_happy_flow(self):
self.assertEqual(test_flow.data.exception_type, TestOutcome.SUCCESS,
'Flow data status should have been success')

def test_giant_flow(self):
"""See that a flow with a large amount of blocks and doesn't crash."""
blocks_num = 1500
MockFlow.blocks = [SuccessBlock] * blocks_num

test_flow = MockFlow()
self.run_test(test_flow)

self.assertTrue(self.result.wasSuccessful(),
'Flow failed when it should have succeeded')

self.assertEqual(self.result.testsRun, 1,
"Flow didn't run the correct number of blocks")

self.validate_blocks(test_flow, successes=blocks_num)

# === Validate data object ===
self.assertTrue(test_flow.data.success,
'Flow data result should have been True')

self.assertEqual(test_flow.data.exception_type, TestOutcome.SUCCESS,
'Flow data status should have been success')

def test_skip_alone(self):
"""Create test flow with only skipped blocks and test its behavior."""
MockFlow.blocks = (SkipBlock, SkipBlock)
Expand Down
22 changes: 22 additions & 0 deletions tests/core/test_suite.py
Expand Up @@ -54,6 +54,28 @@ def test_happy_flow(self):
len(MockTestSuite.components),
'Data members number differs form number of tests')

def test_giant_suite(self):
"""See that a test suite with a large amount of tests doesn't crash."""
tests_amount = 1500
MockTestSuite.components = [SuccessCase] * tests_amount

test_suite = MockTestSuite()
self.run_test(test_suite)

self.assertTrue(self.result.wasSuccessful(),
'Suite failed when it should have succeeded')

self.assertEqual(self.result.testsRun, tests_amount,
"Suite didn't run the correct number of tests")

# === Validate data object ===
self.assertTrue(test_suite.data.success,
'Suite data result should have been True')

self.assertEqual(len(list(test_suite)),
len(MockTestSuite.components),
'Data members number differs form number of tests')

def test_skip_init(self):
"""Create a suite that should skip initialization and validate it."""
MockSuite1.components = (SuccessCase, SuccessCase)
Expand Down

0 comments on commit 04b47f5

Please sign in to comment.