我遇到了问题:我尝试使用pytest-bdd创建测试但我收到错误:
platform darwin -- Python 3.5.2, pytest-3.0.7, py-1.4.32, pluggy-0.4.0
rootdir: /Users/harmatii/PycharmProjects/guru99/bdd, inifile:
plugins: bdd-2.18.2
collected 0 items / 1 errors
No tests found
以下是我的代码来自2个文件:
Scenario Outline: Add New Customer
Given a customer form
When we fill out form with customer information <name>, <email>, <password>
Then verify that page redirects to details of added customer
Examples:
|name | |email | |password |
|Chris | |hhh1@gmail.com | |password |
和我的测试文件:
from pytest_bdd import scenario, given, when, then
from methods.customer import *
from methods.login import *
from methods.is_present import *
@scenario('customers.feature', 'Add New Customer')
def test_customers():
pass
@given('a customer form')
def customer_form(driver):
login(driver, username="mngr91344", password="ubymYtA")
@when('we fill out form with customer information <name>, <email>, <password>')
def add_customer(driver):
add_new_customer(driver, name="Chris", email="hhh1@gmail.com", password="password")
@then('verify that page redirects to details of added customer')
def verify_page(driver):
is_element_present(driver, By.LINK_TEXT, "Customer Registered Successfully!!!")
同一个项目中的其他常规测试(没有bdd)没有问题。
答案 0 :(得分:2)
py.test报告发现1错误:
ValueError: In "parametrize" the number of values (['Chris', '', 'hhh1@gmail.com', '', 'password']) must be equal to the number of names (['name', 'email', 'password'])
从customers.feature
的示例部分删除空列:
Examples:
|name |email |password |
|Chris |hhh1@gmail.com |password |
然后测试集合成功:
$ py.test --collect-only
=========================== test session starts ===========================
platform linux -- Python 3.6.2, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
rootdir: /home/they4kman/.virtualenvs/tmp-5ce0cdbde232a4e/src, inifile:
plugins: bdd-2.18.2
collected 1 item
<Module 'test_customer_steps.py'>
<Function 'test_customers[Chris-hhh1@gmail.com-password]'>