Skip to content

Commit

Permalink
REF: Use pytest warns to capture warning
Browse files Browse the repository at this point in the history
Use pytest's infrastructure
  • Loading branch information
bashtage committed Aug 11, 2018
1 parent b899927 commit b4ae3cd
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions statsmodels/genmod/tests/test_glm_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ def setup_class(cls):
# no wnobs yet in sandwich covariance calcualtion
cls.corr_fact = 1 / np.sqrt(n_groups / (n_groups - 1)) #np.sqrt((wsum - 1.) / wsum)
cov_kwds = {'groups': gid, 'use_correction':False}
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=SpecificationWarning)
with pytest.warns(SpecificationWarning):
cls.res1 = GLM(cpunish_data.endog, cpunish_data.exog,
family=sm.families.Poisson(), freq_weights=fweights
).fit(cov_type='cluster', cov_kwds=cov_kwds)
Expand Down Expand Up @@ -774,19 +773,17 @@ def test_warnings_raised():
gid = np.arange(1, 17 + 1) // 2

cov_kwds = {'groups': gid, 'use_correction': False}
with warnings.catch_warnings(record=True) as w:
with pytest.warns(SpecificationWarning):
res1 = GLM(cpunish_data.endog, cpunish_data.exog,
family=sm.families.Poisson(), freq_weights=weights
).fit(cov_type='cluster', cov_kwds=cov_kwds)
res1.summary()
assert len(w) >= 1

with warnings.catch_warnings(record=True) as w:
with pytest.warns(SpecificationWarning):
res1 = GLM(cpunish_data.endog, cpunish_data.exog,
family=sm.families.Poisson(), var_weights=weights
).fit(cov_type='cluster', cov_kwds=cov_kwds)
res1.summary()
assert len(w) >= 1


weights = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3]
Expand Down

0 comments on commit b4ae3cd

Please sign in to comment.