Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest - no tests ran

I'm using pytest and selenium. When I try run my test script:

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()

The message shown is: no tests ran in 0.84 seconds

Could someone help me run this simple test?

like image 722
Rafael C. Avatar asked Dec 18 '15 20:12

Rafael C.


2 Answers

According to the pytest test conventions, your class should start with Test to be automatically picked up by the test discovery mechanism. Call it TestRegisterNewInstructor instead.

Or, subclass the unittest.TestCase:

import unittest

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

Also keep in mind that the .py test script itself must begin with test_ or end with _test in its filename.

like image 184
alecxe Avatar answered Oct 12 '22 02:10

alecxe


As simple as it looks:

  1. Make sure that your file name matches the pattern: test_*.py or *_test.py.
  2. Make sure that your function name starts with the test prefix.

Find more about the pytest conventions here.

like image 39
Nikolay Kulachenko Avatar answered Oct 12 '22 02:10

Nikolay Kulachenko