[pytest-dev] Access fixtures from unittest.TestCase

holger krekel holger at merlinux.eu
Mon Apr 7 13:27:40 CEST 2014


Hi Wolfgang,

On Mon, Apr 07, 2014 at 13:18 +0200, Wolfgang Schnerring wrote:
> Hello Holger,
> 
> * holger krekel <holger at merlinux.eu> [2014-04-07 10:24]:
> > On Fri, Apr 04, 2014 at 11:21 +0200, Wolfgang Schnerring wrote:
> > > is there a way to access a fixture object from inside a unitest.TestCase
> > >   test function?
> > Right, any "usefixture" needs to either have a global side effect
> > or stick some object to "self".
> >         @pytest.fixture(autouse=True)
> >         def set_tmpdir(self, tmpdir):
> >             self.tmpdir = tmpdir
> 
> Thanks for the hint! Using a method of the TestCase as a wrapper
> fixture around the actual fixture is clever, but also a little
> unwieldy... would there be an easy way to introduce an API to make 
> that easier?

Thing is that trying to bring pytest fixtures to unittest.TestCase's
methods directly is very hard, especially given the many
extensions/subclasses that people use.  If unittest had a plugin
system that would help.

do you have to inherit unittest.TestCase, btw? 
If you don't, all problems go away :)

best,
holger



> Wolfgang
> 
> _______________________________________________
> Pytest-dev mailing list
> Pytest-dev at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
> 


More information about the Pytest-dev mailing list