Skip to content

Commit

Permalink
TST: Restructure test to output debug info on fail
Browse files Browse the repository at this point in the history
Print debug info on failure
  • Loading branch information
bashtage committed Jul 2, 2020
1 parent dabb0bd commit a1a0caf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions statsmodels/stats/tests/test_corrpsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ def test_corr_nearest_factor_sparse(self, dm):
# Generate a test matrix of factors
X = np.zeros((d, dm), dtype=np.float64)
x = np.linspace(0, 2 * np.pi, d)
np.random.seed(10)
rs = np.random.RandomState(10)
for j in range(dm):
X[:, j] = np.sin(x * (j + 1)) + 1e-10 * np.random.randn(d)
X[:, j] = np.sin(x * (j + 1)) + 1e-10 * rs.randn(d)

# Get the correlation matrix
_project_correlation_factors(X)
Expand All @@ -324,7 +324,9 @@ def test_corr_nearest_factor_sparse(self, dm):
np.fill_diagonal(mat, 1)

# Threshold it
mat *= (np.abs(mat) >= 0.35)
mat.flat[np.abs(mat.flat) < 0.35] = 0.0
# Replace line below which left signed 0
# mat *= (np.abs(mat) >= 0.35)
smat = sparse.csr_matrix(mat)

try:
Expand All @@ -340,6 +342,10 @@ def test_corr_nearest_factor_sparse(self, dm):
except AssertionError as err:
if PLATFORM_WIN32:
pytest.xfail('Known to randomly fail on Win32')
# Some debugging information for CI runs that randomly fail
locs = np.where(~np.isclose(mat_dense, mat_sparse, rtol=.25, atol=1e-3))
print(mat_sparse[locs])
print(mat_dense[locs])
raise err

# Test on a quadratic function.
Expand Down

0 comments on commit a1a0caf

Please sign in to comment.