-
Notifications
You must be signed in to change notification settings - Fork 637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatters: add steps.undefined, unused and undefinedunused #1089
Open
djasa
wants to merge
1
commit into
behave:main
Choose a base branch
from
djasa:dj/formatter-steps.failing
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For testing of behave repository itself, it'd be useful to have formatters that would report just faulty steps. The StepsUsageFormatter implementing 'steps.usage' formatter already does this. This commits just adds derived classes implementing: * steps.undefined formatter listing just the undefined steps * steps.unused formatter listing just the unused steps * steps.unusedundefined listing both Note: Due to the way how behave parses steps, in case of typo in a step or param with a wrong tyep, the faulty step will appear in both listings. This is motivation for the third formatter which adds both.
Example use with few scenarios and
This output is produced with: test_step_sanity.pyimport pytest
import subprocess
import sys
import warnings
_behave = ("behave", "--dry", "--no-snippets", "--no-summary", "-f")
def test_undefined_sane():
res = subprocess.run([*_behave, "steps.undefined", "features/scenarios/sane.feature"])
assert res.returncode == 0
def test_undefined_all():
res = subprocess.run([*_behave, "steps.undefined"])
assert res.returncode == 0
def test_unusedundefined_all():
res = subprocess.run([*_behave, "steps.unusedundefined"])
assert res.returncode == 0
def test_warn_on_unused(capfd):
res = subprocess.run([*_behave, "steps.unused"])
cap = capfd.readouterr()
if res.returncode != 0:
warnings.warn(UserWarning(f"Unused steps encountered:\n\n{cap.out}")) features/steps/steps.py$ cat features/steps/steps.py
from behave import given, when, then
@given("unused step")
def step_unused():
very()
complicated()
code()
here()
@given("that step impls exist")
@when("feature is ok")
@then("we're good!")
def step_ok():
return True
@then("""we have "{num:d}" errors""")
def verify_num(num):
assert isinstance(num, int) features/scenarios/sane.featureFeature: Sane
Scenario: Perfect!
Given that step impls exist
When feature is ok
Then we're good! features/scenarios/broken.featureFeature: Broken
Scenario: Broken
Given step does not exist
When we're good!
Then we have "zero" errors |
An alternative approach using |
jenisys
force-pushed
the
main
branch
4 times, most recently
from
April 22, 2023 17:20
fe1ca4d
to
fcfe5af
Compare
jenisys
force-pushed
the
main
branch
2 times, most recently
from
May 14, 2024 22:39
0a4d73b
to
2c11d2e
Compare
jenisys
force-pushed
the
main
branch
2 times, most recently
from
May 26, 2024 15:00
3e51dda
to
c6ab01c
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For testing of behave repository itself, it'd be useful to have formatters that would report just faulty steps.
The StepsUsageFormatter implementing 'steps.usage' formatter already does this. This commits just adds derived classes implementing:
Note:
Due to the way how behave parses steps, in case of typo in a step or param with a wrong tyep, the faulty step will appear in both listings. This is motivation for the third formatter which adds both and may be most useful for projects without many unused steps. :)