On Thu, Apr 07, 2011 at 12:29 -0400, Vyacheslav Rafalskiy wrote:
> >> >> 3. In my pytest_configure() there are numerous conditions when it can
> >> >> fail. For this
> >> >> conditions I have exceptions with specially crafted messages, intended
> >> >> for different
> >> >> people. Now they are gone, replaced by a long and scary listing with 
> >> >> every line
> >> >> prepended with INTERNALERROR. What is internal about it? Can I continue 
> >> >> managing
> >> >> my configuration errors?
> >> >
> >> > Sure, you should be able to. I guess it was a bit of an incident that
> >> > failures in pytest_configure were shown nicely.  I am not quite sure
> >> > immediately what the best way to relay "global" configuration messages
> >> > to the user is.  If you'd use "funcargs" and the "session" scope for
> >> > setting up resources then it would show nicely.  Feel free to open
> >> > a feature/enhancement request to have py.test show failures
> >> > in sessionstart or configure hooks in a way that helps you.
> >> > This way we can write a specific test and make sure it works
> >> > also in the future.
> >>
> >> If I understand correctly, using funcargs means that every test function
> >> of hundreds I have in several suites should include a reference to the
> >> global setup funcarg. It seems a non-starter.
> >>
> >> I guess I will stick to the old version and try to think of something
> >>  to enter in a feature request.
> >
> > sure, makes sense.  isn't your main issue that upon actual test start
> > (after collection) you want to do some configuration steps which might
> > result in error conditions which you'd like to see nicely reported to
> > the user?
> 
> That's exactly my point.
> 
> >(sidenote: configure and even sessionstart hooks are both a bit
> > not 100% right because they happen even on the master side of a distributed
> > test run and the master side does not collect or run tests at all)
> 
> I see. Perhaps something like setup_package() in the top-level __init__.py
> could be a solution?

I guess you mean an __init__.py file of a test directory.
With a layout of test dirs within an application this might mean
one has to put this setup into the main package __init__.py
and mixing test code and application code is often not a good idea.

So i'd rather put it into a conftest.py file as a normal hook.
Maybe "pytest_pyfunc_setup(request)" would be good where request
is the same object as for the funcarg factories.

You could then write:

    # content of conftest.py
    def pytest_pyfunc_setup(request):
        val = request.cached_setup(setup=makeval, scope="session")
        # use val for some global setting of the package

Alternatively we could see to call something like:

    def pytest_setup_testloop(config):
        val = makeval()
        # use val for some global setting of the package
        
    def pytest_teardown_testloop(config):
        ...

which would be called once for a test process.

best,
holger
        
> Vyacheslav
> _______________________________________________
> py-dev mailing list
> py-dev@codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev
> 
_______________________________________________
py-dev mailing list
py-dev@codespeak.net
http://codespeak.net/mailman/listinfo/py-dev

Reply via email to