Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how do I run different setup/teardown functions for each test ? #24

Closed
z00m1n opened this issue Jun 13, 2012 · 1 comment
Closed

how do I run different setup/teardown functions for each test ? #24

z00m1n opened this issue Jun 13, 2012 · 1 comment

Comments

@z00m1n
Copy link

z00m1n commented Jun 13, 2012

I am trying to use runtests(...) to unit-test my stored procedures. What I basically would like to do is

  1. insert/copy some test-data into the database
  2. run a test
  3. remove the test-data
    and repeat these three steps for each test function.

I thought I could achieve this by creating a setup function for step 1 and a teardown function for step 3. However, there does not seem to be a way to define which setup/teardown function I want to run for which test function; according to the docs, all test functions just run all functions whose names start with setup in alphabetical order. I don't need more than one setup/teardown function per test, I just need a different one each time.

Am I generally misunderstanding something here or does pgTAP assume all tests use the same setup/teardown ?

@theory
Copy link
Owner

theory commented Jun 13, 2012

If you need a different one for each test, I think you don't want setup and teardown. Just call your setup function as the first thing you do in the test function. Also, don't worry about removing the data after the test runs: each test function runs in its own transaction, so any data inserted in the test will be rolled back when the test function returns.

HTH,

David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants