<div dir="ltr">While it's difficult to debug without seeing your actual test code (your example doesn't use session or setup_session), it seems like you may be close. If your fixture's name is 'setup_session', that's the name you need to use within the test function - not 'session'.<br>
<div class="gmail_extra"><br></div><div class="gmail_extra">cheers<br>Brianna<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 25 October 2013 08:02, Paradox <span dir="ltr"><<a href="mailto:paradox@pobox.com" target="_blank">paradox@pobox.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am trying to understand fixtures and how they are used. I am writing tests for my program that interacts with an Sqlite database using Sqlalchemy. I am working on Python 2.7.5 in Ubuntu 13.10.<br>
<br>
My setup_session fixture is:<br>
<br>
=================<br>
@pytest.fixture (autouse = True)<br>
def setup_session():<br>
db_file = 'database.db'<br>
engine = create_engine('sqlite:///' + db_file, echo = True)<br>
Base = declarative_base()<br>
Session = sessionmaker(bind=engine)<br>
session = Session()<br>
return session<br>
==================<br>
<br>
Then when I try to use that fixture in a test it is something like:<br>
==================<br>
def test_get_id_of_row(setup_<u></u>session):<br>
assert(get_id_of_row('cell known to be in test data')==1)<br>
==================<br>
<br>
I am getting an error:<br>
==================<br>
NameError: global name 'session' is not defined<br>
==================<br>
<br>
Shouldn't that be taken care of by passing the setup_session fixture to the test function? There is something I don't get about fixtures and would appreciate any pointers on where to read to better understand, I have read the <a href="http://pytest.org" target="_blank">pytest.org</a> site on fixtures several times and it is still not sinking in!<br>
<br>
thomas<br>
<br>
______________________________<u></u>_________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.<u></u>org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/<u></u>listinfo/testing-in-python</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>They've just been waiting in a mountain for the right moment: <a href="http://modernthings.org/">http://modernthings.org/</a>
</div></div>