Skip to content

Commit 7fd1819

Browse files
committed
Use rmtree to delete CSV files in test.
1 parent 2eccbda commit 7fd1819

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test/test_sample.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import unittest
1313
from multiprocessing import cpu_count
1414
import pickle
15+
import pytest
1516
from test import CustomTestCase
1617
from time import time
1718

@@ -1929,10 +1930,11 @@ def test_json_edges(self):
19291930
self.assertTrue(np.isnan(fit.stan_variable("nan_out")[0]))
19301931
self.assertTrue(np.isinf(fit.stan_variable("inf_out")[0]))
19311932

1932-
def test_mcmc_serialization(self, stanfile='bernoulli.stan'):
1933-
# This test must have a name with lexicographical less than any test
1934-
# that uses the `without_import` context manager because the latter uses
1935-
# `reload` with side effects that affect the consistency of classes.
1933+
@pytest.mark.order(before="test_no_xarray")
1934+
def test_serialization(self, stanfile='bernoulli.stan'):
1935+
# This test must before any test that uses the `without_import` context
1936+
# manager because the latter uses `reload` with side effects that affect
1937+
# the consistency of classes.
19361938
stan = os.path.join(DATAFILES_PATH, stanfile)
19371939
bern_model = CmdStanModel(stan_file=stan)
19381940

@@ -1946,8 +1948,7 @@ def test_mcmc_serialization(self, stanfile='bernoulli.stan'):
19461948
)
19471949
# Dump the result (which assembles draws) and delete the source files.
19481950
dumped = pickle.dumps(bern_fit1)
1949-
for filename in bern_fit1.runset.csv_files:
1950-
os.unlink(filename)
1951+
shutil.rmtree(bern_fit1.runset._output_dir)
19511952
# Load the serialized result and compare results.
19521953
bern_fit2: CmdStanMCMC = pickle.loads(dumped)
19531954
variables1 = bern_fit1.stan_variables()

0 commit comments

Comments
 (0)