Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Fix test failures when run consecutively
Browse files Browse the repository at this point in the history
Problem:
Running tests twice causes failures

Solution:
Remove the memoize cache before test runs

This would fail if run twice:
./manage.py test --keepdb jetstream.test_tas_api.TestJetstream.test_validate_account

It would fail because the cassettes did not reflect the correct number of
plays, i.e. api calls didn't happen like we expected. Normally cassettes store
the results of a first http call, and intercept and respond to all future calls with the
results of the first. We assert that the cassette was called a certain number
of times. However, django-memoize intercepts the functions that would even
make these http calls, so the cassettes were under-reporting the number of
playbacks.
  • Loading branch information
cdosborn committed Jul 31, 2018
1 parent 33a4596 commit bf68037
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion jetstream/test_tas_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json

import memoize
import freezegun
import vcr
from django.test import TestCase, override_settings, modify_settings
Expand All @@ -23,6 +23,14 @@
class TestJetstream(TestCase):
"""Tests for Jetstream allocation source API"""

def setUp(self):
# Because we use memoize to cache the tacc api, calling tacc_api_get
# doesn't necessarily trigger an http request. This means that a
# cassette will not necessarily be played. In order to test cassette
# playback, we just need to clear the memoize cache
from jetstream.tas_api import tacc_api_get
memoize.delete_memoized(tacc_api_get)

@my_vcr.use_cassette()
def test_validate_account(self, cassette):
"""Test for a valid account based on the business logic assigned by Jetstream"""
Expand Down

0 comments on commit bf68037

Please sign in to comment.