Pytest – no tests ran
Question:
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?
Answers:
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.
self.andBye()
# This definition should be calles in order to be executed.
def andBye(self):
print('Goodbye')
# Run class
Hello()
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.
try add @classmethod on the top of setUP and tearDown.
As simple as it looks:
- Make sure that your file name matches the pattern:
test_*.py
or *_test.py
.
- Make sure that your function name starts with the
test
prefix.
Find more about the pytest conventions here.
If you use conda environment, don’t forget to activate it!
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?
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.
self.andBye()
# This definition should be calles in order to be executed.
def andBye(self):
print('Goodbye')
# Run class
Hello()
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.
try add @classmethod on the top of setUP and tearDown.
As simple as it looks:
- Make sure that your file name matches the pattern:
test_*.py
or*_test.py
. - Make sure that your function name starts with the
test
prefix.
Find more about the pytest conventions here.
If you use conda environment, don’t forget to activate it!