Skip to content

Commit bdc0a94

Browse files
committed
Add missing assert messages
Behave 1.3 has changed the way it prints assert failures to the log. Add an assert failure message to make sure log output is clear and makes sense.
1 parent 15f16d7 commit bdc0a94

5 files changed

Lines changed: 17 additions & 17 deletions

File tree

public/features/steps/calculator_steps.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://github.com/behave/behave.example
33
# License: BSD
44

5-
# pylint: disable=E0102,E0611,C0103
5+
# pylint: disable=E0102,E0611,E1102,C0103
66

77
from behave import given, register_type, then, when
88

@@ -24,15 +24,15 @@ def step_impl(context):
2424

2525
@when('I add "{x:Number}" and "{y:Number}"')
2626
def step_impl(context, x, y):
27-
assert isinstance(x, int)
28-
assert isinstance(y, int)
27+
assert isinstance(x, int), f"Value x is not an int: {x}"
28+
assert isinstance(y, int), f"Value y is not an int: {x}"
2929
context.calculator.add2(x, y)
3030
print(f"Result: {context.calculator.result}")
3131

3232
@then('the calculator returns "{expected:Number}"')
3333
def step_impl(context, expected):
34-
assert isinstance(expected, int)
35-
assert context.calculator.result == expected
34+
assert isinstance(expected, int), f"Expected value is not an int: {expected}"
35+
assert context.calculator.result == expected, f"Unexpected result: {context.calculator.result}"
3636

3737

3838
# file:features/steps/calculator.py

public/features/steps/ninja.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://github.com/behave/behave.example
33
# License: BSD
44

5-
# pylint: disable=E0401,E0602,E0611,C0114,C0116,E0102,W0613,W0614,W0401
5+
# pylint: disable=E0401,E0602,E0611,E1102,C0114,C0116,E0102,W0613,W0614,W0401
66

77
from behave import *
88

@@ -15,7 +15,7 @@ def step_the_ninja_encounters_another_opponent(context):
1515
# -- SETUP/TEARDOWN:
1616
if hasattr(context, "ninja_fight"):
1717
# -- VERIFY: Double-call does not occur.
18-
assert context.ninja_fight is not None
18+
assert context.ninja_fight is not None, "Value for context.ninja_fight should not be None"
1919
context.ninja_fight = None
2020

2121
@given('the ninja has a {achievement_level}')
@@ -34,7 +34,7 @@ def step_attacked_by(context, opponent):
3434
def step_the_ninja_should(context, reaction):
3535
actual_reaction = context.ninja_fight.decision()
3636
print(f"Reaction: {actual_reaction}")
37-
assert reaction == actual_reaction
37+
assert reaction == actual_reaction, f"Unexpected reaction: {actual_reaction}"
3838

3939

4040
# file:features/steps/ninja_fight.py
@@ -54,8 +54,8 @@ def decision(self):
5454
"""
5555
Business logic how a Ninja should react to increase his survival rate.
5656
"""
57-
assert self.with_ninja_level is not None
58-
assert self.opponent is not None
57+
assert self.with_ninja_level is not None, "Value for self.with_ninja_level should not be None"
58+
assert self.opponent is not None, "Value for self.opponent should not be None"
5959
if self.opponent == "Chuck Norris":
6060
return "run for his life"
6161
if "black-belt" in self.with_ninja_level:

public/features/steps/test_support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pylint: disable=E0401,E0611,C0114,C0116,E0102,W0613
1+
# pylint: disable=E0401,E0611,C0114,C0116,E0102,E1102,W0613,W0718
22
from behave import step
33
from behave.runner import Context
44

@@ -11,4 +11,4 @@ def step_impl(context: Context, error_msg):
1111
context.execute_steps(context.text)
1212
except Exception as ex:
1313
actual_error_msg = repr(ex)
14-
assert error_msg in actual_error_msg
14+
assert error_msg in actual_error_msg, f"Term '{error_msg}' not found in actual error message"

public/features/steps/tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://github.com/behave/behave
44
# BSD-2-Clause
55

6-
# pylint: disable=E0602,E0102,W0613,W0614,W0401
6+
# pylint: disable=E0602,E0102,E1102,W0613,W0614,W0401
77

88
from behave import *
99

@@ -14,8 +14,8 @@ def step_impl(context):
1414

1515
@when('we implement a test')
1616
def step_impl(context):
17-
assert True is not False
17+
assert True is not False, "True is not False"
1818

1919
@then('behave will test it for us!')
2020
def step_impl(context):
21-
assert context.failed is False
21+
assert context.failed is False, "context.failed is not False"

public/features/steps/website_steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pylint: disable=E0611,E0102,W0613,W0622,C0411,C0413
1+
# pylint: disable=E0611,E0102,E1102,W0613,W0622,C0411,C0413
22
from behave import given, step
33

44

@@ -24,7 +24,7 @@ def step_impl(context, username, password):
2424
@step('I verify valid login for "{name}"')
2525
def step_impl(context, name):
2626
server: TestObject = context.server
27-
assert server.get_user(context.session_id) is not None
27+
assert server.get_user(context.session_id) is not None, "Login failed!"
2828

2929

3030
@step('I perform server operation "{operation_name}"')

0 commit comments

Comments
 (0)