Pytest - 没有运行测试

2024-09-21 11:06:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是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秒内未运行任何测试

有人能帮我做这个简单的测试吗?


Tags: fromimportself脚本pytestdefdriverselenium
3条回答

尝试在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()

根据^{} test conventions,类应该从Test开始,然后由测试发现机制自动获取。改称为TestRegisterNewInstructor

或者,将unittest.TestCase子类划分为:

import unittest

class RegisterNewInstructor(unittest.TestCase):
    # ...

还要记住,.py测试脚本本身的文件名必须以test_开头。

相关问题 更多 >

    热门问题