Skip to content

Commit

Permalink
Merge 6c4e63f into 927b8a4
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed May 4, 2023
2 parents 927b8a4 + 6c4e63f commit 76d798e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -7,6 +7,7 @@ v3.0.1
*Release date: In development*

- Allow to search in `context.storage` using `[CONTEXT:a.b.c]` replacement when `before_feature` method is not used
- Execute after scenario methods also when a scenario is skipped to assure that scenario preconditions are cleaned

v3.0.0
------
Expand Down
9 changes: 5 additions & 4 deletions toolium/behave/environment.py
Expand Up @@ -207,7 +207,7 @@ def after_scenario(context, scenario):
:param scenario: running scenario
"""
if scenario.status == 'skipped':
return
context.logger.info("The scenario '%s' has been skipped", scenario.name)
elif scenario.status == 'passed':
test_status = 'Pass'
test_comment = None
Expand All @@ -219,11 +219,12 @@ def after_scenario(context, scenario):
context.global_status['test_passed'] = False

# Close drivers
DriverWrappersPool.close_drivers(scope='function', test_name=scenario.name, test_passed=scenario.status == 'passed',
context=context)
DriverWrappersPool.close_drivers(scope='function', test_name=scenario.name,
test_passed=scenario.status in ['passed', 'skipped'], context=context)

# Save test status to be updated later
add_jira_status(get_jira_key_from_scenario(scenario), test_status, test_comment)
if scenario.status != 'skipped':
add_jira_status(get_jira_key_from_scenario(scenario), test_status, test_comment)


def get_jira_key_from_scenario(scenario):
Expand Down
21 changes: 14 additions & 7 deletions toolium/test/behave/test_environment.py
Expand Up @@ -193,8 +193,9 @@ def test_before_scenario_no_driver_feature(start_driver, add_assert_screenshot_m
start_driver.assert_called_once_with(context, True)


@mock.patch('toolium.behave.environment.add_jira_status')
@mock.patch('toolium.behave.environment.DriverWrappersPool')
def test_after_scenario_passed(DriverWrappersPool):
def test_after_scenario_passed(DriverWrappersPool, add_jira_status):
# Create context mock
context = mock.MagicMock()
context.global_status = {'test_passed': True}
Expand All @@ -204,14 +205,16 @@ def test_after_scenario_passed(DriverWrappersPool):

after_scenario(context, scenario)

# Check that close_drivers is called
# Check that close_drivers and add_jira_status are called
assert context.global_status['test_passed'] is True
DriverWrappersPool.close_drivers.assert_called_once_with(context=context, scope='function', test_name='name',
test_passed=True)
add_jira_status.assert_called_once_with(None, 'Pass', None)


@mock.patch('toolium.behave.environment.add_jira_status')
@mock.patch('toolium.behave.environment.DriverWrappersPool')
def test_after_scenario_failed(DriverWrappersPool):
def test_after_scenario_failed(DriverWrappersPool, add_jira_status):
# Create context mock
context = mock.MagicMock()
context.global_status = {'test_passed': True}
Expand All @@ -221,14 +224,16 @@ def test_after_scenario_failed(DriverWrappersPool):

after_scenario(context, scenario)

# Check that close_drivers is called
# Check that close_drivers and add_jira_status are called
assert context.global_status['test_passed'] is False
DriverWrappersPool.close_drivers.assert_called_once_with(context=context, scope='function', test_name='name',
test_passed=False)
add_jira_status.assert_called_once_with(None, 'Fail', "The scenario 'name' has failed")


@mock.patch('toolium.behave.environment.add_jira_status')
@mock.patch('toolium.behave.environment.DriverWrappersPool')
def test_after_scenario_skipped(DriverWrappersPool):
def test_after_scenario_skipped(DriverWrappersPool, add_jira_status):
# Create context mock
context = mock.MagicMock()
context.global_status = {'test_passed': True}
Expand All @@ -238,9 +243,11 @@ def test_after_scenario_skipped(DriverWrappersPool):

after_scenario(context, scenario)

# Check that close_drivers is not called
# Check that close_drivers is called, but add_jira_status not
assert context.global_status['test_passed'] is True
DriverWrappersPool.close_drivers.assert_not_called()
DriverWrappersPool.close_drivers.assert_called_once_with(context=context, scope='function', test_name='name',
test_passed=True)
add_jira_status.assert_not_called()


@mock.patch('toolium.behave.environment.DriverWrappersPool')
Expand Down

0 comments on commit 76d798e

Please sign in to comment.