Skip to content

Commit 17b177d

Browse files
committed
FIXTURE_REWRITE env var will force the test to pass, existing rewriting fixtures
1 parent 8211149 commit 17b177d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ run though, it will pass.
7575
If any difference is found between the database and the test fixture, then
7676
``diff()`` will return the diff as outputed by GNU diff.
7777

78+
Instead of deleting the fixtures manually before running the tests to
79+
regenerate them, just run your tests with FIXTURE_REWRITE=1 environment
80+
variable. This will overwrite the fixtures and make the tests look like it
81+
passed.
82+
7883
See tests and docstrings for crunchy details.
7984

8085
Requirements

dbdiff/fixture.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
)
1919

2020

21+
REWRITE = os.getenv('FIXTURE_REWRITE')
22+
23+
2124
class Fixture(object):
2225
"""
2326
Is able to print out diffs between database and a fixture.
@@ -130,10 +133,11 @@ def assertNoDiff(self, exclude=None): # noqa
130133
131134
If a diff was found it will raise :py:class:`~exceptions.DiffFound`.
132135
"""
133-
if not self.exists:
136+
if REWRITE or not self.exists:
134137
with open(self.path, 'w+') as f:
135138
self.dump(f)
136-
raise FixtureCreated(self)
139+
if not REWRITE:
140+
raise FixtureCreated(self)
137141

138142
unexpected, missing, different = self.diff(exclude=exclude)
139143

0 commit comments

Comments
 (0)