How to use the pytest.warns function in pytest

To help you get started, we’ve selected a few pytest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OmegaK2 / PyPoE / tests / PyPoE / shared / test_decorators.py View on Github external
def run_test(self, decorator, callobj, obj):
        with pytest.warns(DeprecationWarning) as record:
            o = decorator(callobj)
            args = (1, 2, 3)
            kwargs = {'a': 1, 'b': 2, 'c': 3}
            if obj:
                o(obj(), *args, **kwargs)
            else:
                o(*args, **kwargs)
            return record
github Unidata / MetPy / tests / calc / test_kinematics.py View on Github external
def test_no_ageostrophic_geopotential():
    """Test ageostrophic wind calculation with geopotential and no ageostrophic wind."""
    z = np.array([[48, 49, 48], [49, 50, 49], [48, 49, 48]]) * 100. * units('m^2/s^2')
    u = np.array([[-2, 0, 2]] * 3) * units('m/s')
    v = -u.T
    with pytest.warns(FutureWarning):
        uag, vag = ageostrophic_wind(z, 1 / units.sec, 100. * units.meter, 100. * units.meter,
                                     u, v, dim_order='xy')
    true = np.array([[0, 0, 0]] * 3) * units('m/s')
    assert_array_equal(uag, true)
    assert_array_equal(vag, true)
github AxeldeRomblay / MLBox / tests / test_optimiser.py View on Github external
with pytest.warns(UserWarning) as record:
        opt = Optimiser(scoring=mape, n_folds=3)
    assert len(record) == 1
    score = opt.evaluate(None, dict)
    assert -np.Inf <= score

    with pytest.warns(UserWarning) as record:
        opt = Optimiser(scoring=None, n_folds=3)
    assert len(record) == 1
    score = opt.evaluate(None, dict)
    assert -np.Inf <= score

    with pytest.warns(UserWarning) as record:
        opt = Optimiser(scoring="wrong_scoring", n_folds=3)
    assert len(record) == 1
    with pytest.warns(UserWarning) as record:
        score = opt.evaluate(None, dict)
    assert -np.Inf <= score
github onecodex / onecodex / tests / test_api_models.py View on Github external
def test_public_search(ocx, api_data):
    with pytest.warns(DeprecationWarning):
        samples = ocx.Samples.search_public(filename="tmp.fa")
        assert len(samples) == 0
    samples = ocx.Samples.where(filename="tmp.fa", public=True)
    assert len(samples) == 0
github pydata / sparse / tests / test_coo.py View on Github external
def test_warn_on_too_dense():
    import os
    from importlib import reload

    os.environ['SPARSE_WARN_ON_TOO_DENSE'] = '1'
    reload(sparse._settings)

    with pytest.warns(RuntimeWarning):
        sparse.random((3, 4, 5), density=1.0)

    del os.environ['SPARSE_WARN_ON_TOO_DENSE']
    reload(sparse._settings)
github pyproj4 / pyproj / test / test_transformer.py View on Github external
def test_equivalent_proj():
    with pytest.warns(UserWarning):
        proj_to = pyproj.Proj(4326).crs.to_proj4()
    with pytest.warns(FutureWarning):
        transformer = Transformer.from_proj(
            "+init=epsg:4326", proj_to, skip_equivalent=True
        )
    assert transformer._transformer.skip_equivalent
    assert transformer._transformer.projections_equivalent
    assert not transformer._transformer.projections_exact_same
github cogeotiff / rio-cogeo / tests / test_cogeo.py View on Github external
def test_cog_translate_oneBandJpeg(runner):
    """Should work as expected (create cogeo file)."""
    with runner.isolated_filesystem():
        profile = jpeg_profile.copy()
        with pytest.warns(UserWarning):
            cog_translate(
                raster_path_rgb, "cogeo.tif", profile, indexes=(1,), quiet=True
            )
        with rasterio.open("cogeo.tif") as src:
            assert src.compression.value == "JPEG"
            assert src.colorinterp[0] == rasterio.enums.ColorInterp.gray
github quantumblacklabs / kedro / tests / contrib / io / yaml_local / test_yaml_local.py View on Github external
def test_save_version_warning(
        self, versioned_yaml_data_set, load_version, save_version, yaml_data
    ):
        """Check the warning when saving to the path that differs from
        the subsequent load path."""
        pattern = (
            r"Save version `{0}` did not match load version `{1}` "
            r"for YAMLLocalDataSet\(.+\)".format(save_version, load_version)
        )
        with pytest.warns(UserWarning, match=pattern):
            versioned_yaml_data_set.save(yaml_data)
github pyproj4 / pyproj / test / test_crs_cf.py View on Github external
false_northing=0.0,
        )
    )
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == {
        "grid_mapping_name": "oblique_mercator",
        "latitude_of_projection_origin": 10,
        "longitude_of_projection_origin": 15,
        "azimuth_of_central_line": 0.35,
        "false_easting": 0,
        "false_northing": 0,
        "reference_ellipsoid_name": "WGS84",
        "unit": "m",
    }
    with pytest.warns(UserWarning):
        assert crs.to_dict() == {
            "proj": "omerc",
            "lat_0": 10,
            "lonc": 15,
            "alpha": 0.35,
            "gamma": 0.35,
            "k": 1,
            "x_0": 0,
            "y_0": 0,
            "ellps": "WGS84",
            "units": "m",
            "no_defs": None,
            "type": "crs",
        }
    # test CRS with input as lon_0 from the user
    lon0crs_cf = CRS(
github aio-libs / aiohttp-sse / tests / test_sse.py View on Github external
async def test_custom_response_cls(with_subclass):
    class CustomResponse(EventSourceResponse if with_subclass else object):
        pass

    request = make_mocked_request('GET', '/')
    if with_subclass:
        with pytest.warns(RuntimeWarning):
            sse_response(request, response_cls=CustomResponse)
    else:
        with pytest.raises(TypeError):
            sse_response(request, response_cls=CustomResponse)