py.test does not find tests under a class
pycharm, pytest, python, unit-testing
Solution
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')
# this works too
@staticmethod
def test_three():
pass
# this doesn't work
#@classmethod
#def test_three(cls):
# pass
See the docs:
- Group multiple tests in a class
- Conventions for Python test discovery
Problem
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.