问题
I have a 'behave' feature that has a lot of tests on it.
I only need to run a specific scenario for development needs.
How do I do it?
(preferably on the command line)
回答1:
To run only a single scenario you can use -n
with the name of the scenario:
$ behave -n 'clicking the button "foo" should bar the baz'
I'm using single quotes above to keep the name of the scenario as one argument for -n
. Otherwise, the shell will pass each word of the scenario name as a separate argument.
回答2:
If you want to run a single test for that feature, use the -n
or --name
flag which seems to want the text after Scenario:
behave -n 'This is a scenario name'
You can run a feature file by using -i
or --include
flags and then the name of the feature file.
behave -i file_name.feature
or:
behave --include file_name
You can also exclude with the --exclude
flag:
behave -e file_name
For more information check the documentation for command line arguments. There's a lot of useful information hidden in their appendix section.
NOTE: At the time I'm writing this it won't work with Python 3.6 and Behave 1.2.5, due to this issue. (UPDATE: 1.2.6 is out and fixes this, but if you're on python 3.4 that version won't be available from pip so you can workaround this with pip3 install git+https://github.com/behave/behave#1.2.6rc
).
It also seems like you should be able to pass in the text after Feature:
for the -i flag but currently that doesn't work. Somebody remind me to updated if it works again. I also encourage people to check out the wip flag, which allows you to add @wip
to a test, then -wip
will not only run the test but also allow print/logging statements for debugging.
回答3:
Tags provide a couple of options ...
1) Tag the slow ones and then avoid by invoking with the inverse e.g.
behave -t '~@slow_tag_name'
2) However for the most flexibility I'd personally recommend tagging each Scenario with a unique ID. e.g. I use a @YYYY_MM_DD_HHmm_Initials
tag scheme since, this is unique enough and the traceability is useful/interesting. Then you can always simply invoke with the tag and get it to run the Scenario, .e.g
behave @2015_01_03_0936_jh
来源:https://stackoverflow.com/questions/27030233/in-behave-how-do-you-run-a-scenario-only