[TIP] Hint on TestClass

Thijs Engels thijs at buckazoids.com
Wed Jul 11 07:26:05 PDT 2012


Hello all,

I am currently running multiple tests (using py.test) on a series of
objects which are relatively expensive to retrieve. My thinking was to
group the tests on the same object into one class, potentially using the
setup/teardown at class level to retrieve the object under test.

As mentioned there is a series of these objects, hence I would like to
parametrize the class holding all the individual tests. Via the search
on the py.test I actually landed on a page which seems to describe
exactly what I am after:
http://pytest.org/dev/example/resources_attic.html, although I could not
complete figure out the given example with self.db.

This is about what I hoping to archive:
  Use parametrize to run the test in TestSession for a list of
  session_ids.

TestSession:
  def __init__(self, session_id):
    self.session = expensive_database_query(session_id)

  def test_session_id():
    assert session.id > 0

  def test_session_date():
    assert session.date >= date(2012, 1, 1)

  def test_periods():
    assert periods in range(1, 26)

Is the resource_attic link indeed describing what I am after?

Thijs



More information about the testing-in-python mailing list