Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

py.test does not find tests under a class

I am trying to create test classes that aren't unittest based.

This method under this class

class ClassUnderTestTests:      def test_something(self): 

cannot be detected and run when you call py.test from the command line or when you run this test in PyCharm (it's on its own module).

This

def test_something(self): 

same method outside of a class can be detected and run.

I'd like to group my tests under classes and unless I'm missing something I'm following the py.test spec to do that.

Environment: Windows 7, PyCharm with py.test set as the test runner.

like image 746
Michael Avatar asked Nov 29 '13 01:11

Michael


People also ask

Why pytest is not working?

Verify that all test cases names also start with 'test_' word. Verify that you have created pytest. ini file in the root directory. Verify that you have __init__.py file in all directories/sub-directories of the project.

How do you test a class in Python?

First you need to create a test file. Then import the unittest module, define the testing class that inherits from unittest. TestCase, and lastly, write a series of methods to test all the cases of your function's behavior. First, you need to import a unittest and the function you want to test, formatted_name() .

What is the difference between pytest and py test?

To answer the question about the actual command (meaning the invocation of the tool on the command line) in a bit more detail: The py. test invocation is the old and busted joint. pytest is the new hotness (since 3.0).


1 Answers

By convention it searches for

Test prefixed test classes (without an init method)

eg.

# content of test_class.py class TestClass:     def test_one(self):         x = "this"         assert 'h' in x      def test_two(self):         x = "hello"         assert hasattr(x, 'check') 

See the docs here

like image 91
twil Avatar answered Oct 05 '22 17:10

twil