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.
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.
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() .
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With