[英]Pytest - no tests ran
我正在使用 pytest 和硒。 当我尝试运行我的测试脚本时:
import pytest
from selenium import webdriver
from pages import *
from locators import *
from selenium.webdriver.common.by import By
import time
class RegisterNewInstructor:
def setup_class(cls):
cls.driver = webdriver.Firefox()
cls.driver.get("http://mytest.com")
def test_01_clickBecomeTopButtom(self):
page = HomePage(self.driver)
page.click_become_top_button()
self.assertTrue(page.check_instructor_form_page_loaded())
def teardown_class(cls):
cls.driver.close()
显示的消息是:没有测试在 0.84 秒内运行
有人可以帮我运行这个简单的测试吗?
根据pytest
测试约定,您的类应以Test
开头,以便测试发现机制自动选取。 而是将其TestRegisterNewInstructor
。
或者,将unittest.TestCase
子类化:
import unittest
class RegisterNewInstructor(unittest.TestCase):
# ...
还要记住,.py 测试脚本本身必须在其文件名中以_test
开头或以test_
结尾。
尝试在 setUP 和 tearDown 的顶部添加 @classmethod。
你自己上课了吗?
我在这段代码中没有看到你显示你调用类或定义来运行。
例如,在 python 中你运行一个类或定义如下:
class Hello():
# __init__ is a definition runs itself.
def __init__(self):
print('Hello there')
# Call another definition.
self.andBye()
# This definition should be calles in order to be executed.
def andBye(self):
print('Goodbye')
# Run class
Hello()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.