|
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 |
|
7 |
| -from pytest_bdd import given, parsers, then, when |
| 7 | +from pytest_bdd import given, parser, parsers, then, when |
8 | 8 | from pytest_bdd.utils import collect_dumped_objects
|
9 | 9 |
|
10 | 10 |
|
@@ -316,3 +316,25 @@ def _(n):
|
316 | 316 |
|
317 | 317 | objects = collect_dumped_objects(result)
|
318 | 318 | assert objects == ["foo", ("foo parametrized", 1), "foo", ("foo parametrized", 2), "foo", ("foo parametrized", 3)]
|
| 319 | + |
| 320 | + |
| 321 | +def test_step_name_is_cached(): |
| 322 | + """Test that the step name is cached and not re-computed eache time.""" |
| 323 | + step = parser.Step(name="step name", type="given", indent=8, line_number=3, keyword="Given") |
| 324 | + assert step.name == "step name" |
| 325 | + |
| 326 | + # manipulate the step name directly and validate the cache value is still returned |
| 327 | + step._name = "incorrect step name" |
| 328 | + assert step.name == "step name" |
| 329 | + |
| 330 | + # change the step name using the property and validate the cache has been invalidated |
| 331 | + step.name = "new step name" |
| 332 | + assert step.name == "new step name" |
| 333 | + |
| 334 | + # manipulate the step lines and validate the cache value is still returned |
| 335 | + step.lines.append("step line 1") |
| 336 | + assert step.name == "new step name" |
| 337 | + |
| 338 | + # add a step line and validate the cache has been invalidated |
| 339 | + step.add_line("step line 2") |
| 340 | + assert step.name == "new step name\nstep line 1\nstep line 2" |
0 commit comments