[TIP] Getting Weird Coverage Reports

holger krekel holger at merlinux.eu
Tue Nov 29 07:53:12 PST 2011


On Tue, Nov 29, 2011 at 22:51 +1100, meme dough wrote:
> > Right. I am thinking of calling a setup_directory|teardown_directory(X)
> > in respective conftest.py files.
> >
> > FWIW there were some users on the IRC channels requesting the equivalent
> > of nose's setup_package/teardown_package.  I'd rather like to use a
> > different approach - call setup_directory(testdata) where "testdata"
> > is a global object on which you can set attributes. This very object
> > can be accessed from test functions as a funcarg:
> >
> >    def test_function(testdata):
> >        # access globally shared test resources as attributes on "testdata"
> >
> > it probably would also make sense to make the config object available
> > to setup_directory so that one can create global resources depending
> > on command line options etc. Either as an attribute on testdata or
> > as a second argument to the setup/teardown functions.
> >
> > Makes sense to you?
> 
> Sounds good.  When would the setup_directory be called?  If there are
> tests but filtered with -k such that a directory won't have any tests
> run will that avoid the setup_directory / teardown_directory for that
> directory?

I agree this is how it should work - only just-in-time call
setup_directory if a test in that directory is about to be executed.
Do you feel like opening an issue https://bitbucket.org/hpk42/pytest/issues/new
so i have someone to bounce and ask for review when it's implemented? :)

And do you think we should also add nose-compatible calls to
setup_package() of respective __init__.py files? Would make
ad-hoc running of nose-based test suites easier i guess.

holger



More information about the testing-in-python mailing list