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

Provide method to teardown fixture data #89

Open
sproutworks opened this issue Mar 12, 2021 · 4 comments
Open

Provide method to teardown fixture data #89

sproutworks opened this issue Mar 12, 2021 · 4 comments
Labels

Comments

@sproutworks
Copy link

I've run into a situation where my build fails depending on the order of the tests and the nature of their foreign key relationships. I am using the UseAlterConstraint method with Postgres, and not running tests in parallel.

For example:

Test 1 creates fixtures for Table A & Table B. Table A has a record which references some record in Table B.
Test 2 only creates fixtures in Table B. Because there is leftover data in table A from test 1, now test 2 fails when testfixtures tries to clear Table B.

What I had to do to solve this is to copy the logic to make the constraints deferrable (I am using Postgres). Then I can do a teardown at the end of each test where I delete all the fixture data.

So what I am looking for is a method something like:
fixtures.Unload()

This would remove everything created by fixtures.Load(), to avoid potential conflicts with subsequent tests.

@Balake
Copy link

Balake commented Apr 14, 2021

I've also run into something similar and would benefit from something like this.

EDIT: I was under the impression this was already happening from:

Before the execution of every test, the test database is cleaned and the fixture data is loaded into the database

so maybe I'm doing something wrong?

EDIT2:

I'm doing:

func TestX(t *testing.T) {
    tests := []testType{ ... }
    for _, test := range tests {
        t.Run(test.Name, func(t *testing.T) {
             prepare()
             ...
        }
    }
}

@andreynering
Copy link
Contributor

Hi @sproutworks,

I have the impression that the problem you're having is a consequence of how you're using testfixtures. Ideally, you should load all tables before every test.

If you're loading only some tables than surely you can have integrity problems, but I think it's not the library's responsibility to prevent that.

@masv87
Copy link

masv87 commented Dec 7, 2021

Hi @sproutworks,

I have the impression that the problem you're having is a consequence of how you're using testfixtures. Ideally, you should load all tables before every test.

If you're loading only some tables than surely you can have integrity problems, but I think it's not the library's responsibility to prevent that.

Hi, @andreynering! We are facing the same issue and would be so glad if there is a possibility to wipe test data after running a test. I hope this PR - #110 could give us such opportunity. In this case library's user would have a possibility to choose if he needs or not to clear the test data.

@brpaz
Copy link

brpaz commented Dec 5, 2022

@andreynering +1 to this. I think it´s a common use case to have a different set of data for different test scenarios.

Ideally, fixtures should be able to clean themselves after each test.

Is there any chance of #110 to be reviewed and merged?

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

No branches or pull requests

5 participants