I think it's best to think of the xunit-style setup and teardown as part of
the actual test - as in, if you're blindly translating this:

    class SomethingTest(TestCase):
        def setUp(self):
            self.doop = 1

        def tearDown(self):
            del self.doop

        def test_something(self):
            assert self.doop == 1

        def test_something_else(self):
            assert self.doop != 2

you'd get this:


    class TestSomething(object):
        def setUp(self):
            self.doop = 1

        def tearDown(self):
            del self.doop

        def test_something(self):
            self.setUp()
            try:
                assert self.doop == 1
            finally:
                self.tearDown()

        def test_something_else(self):
            self.setUp()
            try:
                assert self.doop != 2
            finally:
                self.tearDown()

I'm not sure how to demonstrate an equivalent to setUpClass, but my point
is that fixtures shouldn't even be able to tell that setup and teardown
aren't part of the actual test method unless they look for it.

As for allowing funcargs to the setup functions, I think marking them as
@pytest.fixture(autouse=True) would be great. I do think that it'd be more
intuitive for people who are used to xunit style if the @pytest.setup thing
being discussed on the other thread was made available.

On Sun, Dec 16, 2012 at 12:24 PM, holger krekel <hol...@merlinux.eu> wrote:

> On Sun, Dec 16, 2012 at 13:21 +0100, Ronny Pfannschmidt wrote:
> > sounds like the correct curse of action else legacy tests cant be
> > integrated with fixtures propperly
>
> "curse of action" ... like that one :)
>
> > i wonder if we should go as far as allowing fixtures to be arguments
> > to pytest xunit test functions
>
> that'd be tricky at least for setup_module and setup_method/function which
> support a positional argument.  Note that you can easily turn your setup
> function into one that accepts fixtures:
>
>     @pytest.fixture
>     def setup_method(self, request, tmpdir, ...):
>         ...
>
> In this case there is no positional argument but you can get the
> current function under test via ``request.function``.
> I think it's clearer to add that extra line.
>
> holger
>
> > On 12/16/2012 12:23 PM, holger krekel wrote:
> > >Hi all,
> > >
> > >Currently, if you define e.g. an autouse fixture function it is going to
> > >be called _after_ the xUnit setup functions.  This is especially
> > >surprising when you do a session-scoped autouse fixture.  I am wondering
> > >if we could reverse the order, i.e. call fixture functions (including
> > >autouse-fixtures of course) ahead of xUnit setup methods.
> > >
> > >any thoughts?
> > >
> > >holger
> > >_______________________________________________
> > >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