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 import By
import time

class RegisterNewInstructor:
    def setup_class(cls):
        cls.driver = webdriver.Firefox()

    def test_01_clickBecomeTopButtom(self):
        page = HomePage(self.driver)

    def teardown_class(cls):

The message shown is: no tests ran in 0.84 seconds

Could someone help me run this simple test?

Asked By: Rafael C.



Did you execute the class itself?
I don’t see in this code you are showing that you call the class or definitions to run.

For example, in python you run a class or definition like this:

class Hello():
    # __init__ is a definition runs itself. 
    def __init__(self): 
        print('Hello there')
        # Call another definition. 

    # This definition should be calles in order to be executed. 
    def andBye(self):

# Run class 
Answered By: Tenzin

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.

Answered By: alecxe

try add @classmethod on the top of setUP and tearDown.

Answered By: Chien Huang

As simple as it looks:

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

Find more about the pytest conventions here.

Answered By: Nikolay Kulachenko

If you use conda environment, don’t forget to activate it!

Answered By: natielle
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.