Bruno Oliveira <nicoddemus@...> writes:

> 
> 
> 
> Hi Dave,
> Using plain pytest that is currently not possible, and I’m not aware 
of any plugin which allows this.
> You can implement your own collection rules by implementing the 
pytest_pycollect_makeitem hook. I suggest taking a look at how pytest 
itself does it to get some guidance, but I think this would be enough 
for your case:
> # conftest.py
> import inspect
> 
> class X: pass
> 
> def pytest_pycollect_makeitem(collector, name, obj):        
>     if inspect.isclass(obj) and issubclass(obj, X):    
>         Class = collector._getcustomclass("Class")
>         return Class(name, parent=collector)
> 
> # test_foo.py
> from conftest import X
> 
> class Foo(X):
>     def test_foo(self):
>         pass
> 
> test_foo.py::Foo::test_foo PASSED
> 
> ========================== 1 passed in 0.13 seconds 
===========================
> Cheers,Bruno.


Cheers for the detailed answer! I'll give it a go as I think it's a 
nicer way to explicitly mark classes for testing.


Thanks,
Dave
_______________________________________________
pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to