diff --git a/lib/bx/binned_array_tests.py b/lib/bx/binned_array_tests.py index c61c867..be99d8d 100644 --- a/lib/bx/binned_array_tests.py +++ b/lib/bx/binned_array_tests.py @@ -16,18 +16,17 @@ FileBinnedArray, ) +import pytest + # Bigger values take longer, but excercise more bins CHUNK_SIZE_RANDOM = 945 CHUNK_SIZE_ZEROS = 897 # CHUNK_SIZE_RANDOM=9456 # CHUNK_SIZE_ZEROS=8972 -source = target = None - -def setup(): - global source - global target +@pytest.fixture(scope="module") +def source_target(): source = [] for _ in range(13): if random() < 0.5: @@ -43,7 +42,8 @@ def setup(): return source, target -def test_simple(): +def test_simple(source_target): + source, target = source_target # Verify for i in range(len(source)): assert source[i] == target[i], "No match, index: %d, source: %f, target: %f, len( source ): %d" % ( @@ -66,7 +66,8 @@ def test_simple(): ) -def test_file(): +def test_file(source_target): + source, target = source_target # With a file (zlib) target.to_file(open("/tmp/foo", "wb")) target2 = FileBinnedArray(open("/tmp/foo", "rb")) @@ -87,7 +88,8 @@ def test_file(): ) -def test_file_lzo(): +def test_file_lzo(source_target): + source, target = source_target # With a file (lzo) target.to_file(open("/tmp/foo3", "wb"), comp_type="lzo") target3 = FileBinnedArray(open("/tmp/foo3", "rb")) @@ -109,7 +111,8 @@ def test_file_lzo(): ) -def test_binned_array_writer(): +def test_binned_array_writer(source_target): + source, target = source_target # Test with ba writer o = open("/tmp/foo4", "wb") w = BinnedArrayWriter(o, 128, comp_type="lzo")