Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions stor/test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import inspect
import mock
import unittest
import os
import sys
import unittest
import uuid

import dxpy
import vcr

from stor import Path
from stor import s3
from stor import settings
from stor.s3 import S3Path
from stor.swift import SwiftPath
from stor import settings


class SwiftTestMixin(object):
Expand Down Expand Up @@ -198,6 +198,7 @@ class DXTestMixin(object):
which records all http interactions for playback.
"""
vcr_enabled = True # switch this to False to deactivate vcr recording
delete_on_exception = True # switch to False to persist cassettes on exception

def setUp(self): # pragma: no cover
"""Sets us vcr cassettes if enabled, and starts patcher for time.sleep.
Expand All @@ -210,6 +211,7 @@ def setUp(self): # pragma: no cover
super(DXTestMixin, self).setUp()
self.cassette = None
if self.vcr_enabled:
self.addCleanup(self.cleanup_cassettes)
myvcr = vcr.VCR(cassette_library_dir=self._get_cassette_library_dir(),
filter_headers=['authorization'])
cm = myvcr.use_cassette(self._get_cassette_name())
Expand All @@ -220,6 +222,14 @@ def setUp(self): # pragma: no cover
self.addCleanup(patcher.stop)
patcher.start()

def cleanup_cassettes(self):
if self.delete_on_exception:
if any(sys.exc_info()):
vcr_path = Path(self._get_cassette_library_dir()
).joinpath(self._get_cassette_name())
if vcr_path.isfile():
vcr_path.remove()

def _get_cassette_library_dir(self):
"""Sets up different directories for Python 2 and 3, as well as by TestClass
subdir, because cassette recording and playback are in different formats
Expand Down