python - Pytest - 没有测试运行

标签 python automated-tests pytest

我正在使用 pytest 和 selenium。当我尝试运行我的测试脚本时:

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 conventions ,您的类应该以 Test 开头,以便测试发现机制自动选取。将其称为 TestRegisterNewInstructor

或者,子类化 unittest.TestCase:

import unittest

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

另请记住,.py 测试脚本本身的文件名必须以 test_ 开头或以 _test 结尾。

关于python - Pytest - 没有测试运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34363388/

相关文章:

python - 计算较大列表中每个列表的第 n 项的频率

python - python中好的自动化系统测试框架

django - 如何使用 django-pytest 跟踪 Django 重定向?

python - pytest django 从 yaml 文件加载数据库数据

python - 使用 TF-IDF 向量大小进行 NLP 情感分析

python - 如何使用 Python 将任何字符串转换为有效的自定义模式?

python - 在 Python 中跳过代码行?

google-chrome - TestCafe:在文本字段中输入的文本是向后的

javascript - Protractor 3.0.0 和 Cucumber 自动化测试

python - 在特定的 pytest 标记上禁用 autouse fixtures