[TIP] Learning fixtures in py.test :p:
Paradox
paradox at pobox.com
Fri Oct 25 07:45:49 PDT 2013
On 10/25/2013 05:52 AM, holger krekel wrote:
> When pytest runs a test function it looks
> at the argument _names_ a test function requires. And then discovers
> the fixture functions by _name_. If you wanted to use a
> `sqlsession`` object you could do::
>
> @pytest.fixture
> def sqlsession():
> ... # like in your code
> Session = sessionmaker(bind=engine)
> return Session()
>
> and then in a test:
>
> def test_sql_something(sqlsession):
> # use sqlsession instance in test
>
Thanks (to you and Brianna), this is just what I needed, pointed me to
where my basic misunderstanding is (and some of my poor coding practice
in the code I am testing).
thomas
More information about the testing-in-python
mailing list