Repository: PlasmaPy/PlasmaPy

Issue:
Warn, not raise with UserWarning
That seems to have landed under raise clauses for a whole bunch of lines in our code. We'll have to fix that, update tests and the docs as well.

Discussion:

Patch:
diff --git a/plasmapy/physics/parameters.py b/plasmapy/physics/parameters.py
index 19f4a1c3..198a5e99 100644
--- a/plasmapy/physics/parameters.py
+++ b/plasmapy/physics/parameters.py
@@ -144,13 +144,13 @@ def Alfven_speed(B, density, ion="p+", z_mean=None):
         If the density is negative, or the ion mass or charge state
         cannot be found.
 
-    UserWarning
-        if units are not provided and SI units are assumed.
-
     Warns
     -----
     ~plasmapy.utils.RelativityWarning
-        If the Alfven velocity exceeds 10% of the speed of light
+        If the Alfven velocity exceeds 5% of the speed of light
+
+    ~astropy.units.UnitsWarning
+        if units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -266,9 +266,13 @@ def ion_sound_speed(T_e,
     ~astropy.units.UnitConversionError
         If the temperature is in incorrect units.
 
-    UserWarning
-        If the ion sound speed exceeds 10% of the speed of light, or
-        if units are not provided and SI units are assumed.
+    Warns
+    -----
+    RelativityWarning
+        If the ion sound speed exceeds 5% of the speed of light.
+
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -370,9 +374,13 @@ def thermal_speed(T, particle="e-", method="most_probable"):
         The particle temperature is invalid or particle cannot be used to
         identify an isotope or particle
 
-    UserWarning
-        If the particle thermal speed exceeds 10% of the speed of light, or
-        if units are not provided and SI units are assumed.
+    Warns
+    -----
+    RelativityWarning
+        If the ion sound speed exceeds 5% of the speed of light, or
+
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -474,9 +482,13 @@ def kappa_thermal_speed(T, kappa, particle="e-", method="most_probable"):
         The particle temperature is invalid or particle cannot be used to
         identify an isotope or particle.
 
-    UserWarning
-        If the particle thermal speed exceeds 10% of the speed of light, or
-        if units are not provided and SI units are assumed.
+    Warns
+    -----
+    RelativityWarning
+        If the particle thermal speed exceeds 5% of the speed of light, or
+
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -847,8 +859,10 @@ def gyrofrequency(B, particle='e-', signed=False, Z=None):
         If the magnetic field contains invalid values or particle cannot be
         used to identify an particle or isotope
 
-    UserWarning
-        If units are not provided and SI units are assumed
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -946,8 +960,10 @@ def gyroradius(B, particle='e-', *, Vperp=np.nan * u.m / u.s, T_i=np.nan * u.K):
     ValueError
         If any argument contains invalid values
 
-    UserWarning
-        If units are not provided and SI units are assumed
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -1049,8 +1065,10 @@ def plasma_frequency(n, particle='e-', z_mean=None):
         If `n_i` contains invalid values or particle cannot be used to
         identify an particle or isotope.
 
-    UserWarning
-        If units are not provided and SI units are assumed
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -1133,8 +1151,10 @@ def Debye_length(T_e, n_e):
     ValueError
         If either argument contains invalid values
 
-    UserWarning
-        If units are not provided and SI units are assumed
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -1196,8 +1216,10 @@ def Debye_number(T_e, n_e):
     ValueError
         If either argument contains invalid values
 
-    UserWarning
-        If units are not provided and SI units are assumed
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Returns
     -------
@@ -1268,8 +1290,10 @@ def inertial_length(n, particle='e-'):
     ValueError
         The particle density does not have an appropriate value.
 
-    UserWarning
-        If units are not provided and SI units are assumed.
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -1324,8 +1348,10 @@ def magnetic_pressure(B):
         If the magnetic field strength is not a real number between
         +/- infinity.
 
-    UserWarning
-        If units are not provided and SI units are assumed.
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -1386,8 +1412,10 @@ def magnetic_energy_density(B: u.T):
         If the magnetic field strength does not have an appropriate.
         value.
 
-    UserWarning
-        If units are not provided and SI units are assumed.
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -1443,17 +1471,19 @@ def upper_hybrid_frequency(B, n_e):
     Raises
     ------
     TypeError
-        If either of B or n_e is not a Quantity.
+        If either of `B` or `n_e` is not a Quantity.
 
     ~astropy.units.UnitConversionError
-        If either of B or n_e is in incorrect units.
+        If either of `B` or `n_e` is in incorrect units.
 
     ValueError
-        If either of B or n_e contains invalid values or are of
+        If either of `B` or `n_e` contains invalid values or are of
         incompatible dimensions.
 
-    UserWarning
-        If units are not provided and SI units are assumed.
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -1521,8 +1551,10 @@ def lower_hybrid_frequency(B, n_i, ion='p+'):
         incompatible dimensions, or ion cannot be used to identify an
         ion or isotope.
 
-    UserWarning
-        If units are not provided and SI units are assumed.
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
diff --git a/plasmapy/physics/quantum.py b/plasmapy/physics/quantum.py
index 8e60344d..568c3a34 100644
--- a/plasmapy/physics/quantum.py
+++ b/plasmapy/physics/quantum.py
@@ -19,6 +19,9 @@
 
 # TODO: Use @check_relativistic and @particle_input
 
+@utils.check_quantity({
+    'V': {'units': u.m/u.s, 'can_be_negative': True}
+    })
 def deBroglie_wavelength(V, particle):
     r"""
     Calculates the de Broglie wavelength.
@@ -52,9 +55,8 @@ def deBroglie_wavelength(V, particle):
 
     Warns
     -----
-    UserWarning
-        If `V` is not a `~astropy.units.Quantity`, then a `UserWarning`
-        will be raised and units of meters per second will be assumed.
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
 
     Notes
     -----
@@ -150,8 +152,8 @@ def thermal_deBroglie_wavelength(T_e):
 
     Warns
     -----
-    UserWarning
-        If units are not provided and SI units are assumed.
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -203,8 +205,8 @@ def Fermi_energy(n_e):
 
     Warns
     -----
-    UserWarning
-        If units are not provided and SI units are assumed.
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -264,8 +266,8 @@ def Thomas_Fermi_length(n_e):
 
     Warns
     -----
-    UserWarning
-        If units are not provided and SI units are assumed.
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -339,8 +341,8 @@ def Wigner_Seitz_radius(n: u.m**-3):
 
     Warns
     -----
-    UserWarning
-        If units are not provided and SI units are assumed.
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -397,8 +399,8 @@ def chemical_potential(n_e: u.m ** -3, T: u.K):
 
     Warns
     -----
-    UserWarning
-        If units are not provided and SI units are assumed.
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
@@ -498,8 +500,8 @@ def chemical_potential_interp(n_e, T):
 
     Warnings
     --------
-    UserWarning
-        If units are not provided and SI units are assumed.
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
diff --git a/plasmapy/physics/relativity.py b/plasmapy/physics/relativity.py
index 84517ff1..5bfa9cd4 100644
--- a/plasmapy/physics/relativity.py
+++ b/plasmapy/physics/relativity.py
@@ -5,7 +5,10 @@
 from plasmapy import atomic, utils
 
 
-def Lorentz_factor(V):
+@utils.check_quantity({
+    'V': {'units': u.m/u.s, 'can_be_negative': True}
+    })
+def Lorentz_factor(V: u.m/u.s):
     r"""
     Return the Lorentz factor.
 
@@ -31,9 +34,10 @@ def Lorentz_factor(V):
     ValueError
         If the magnitude of `V` is faster than the speed of light.
 
-    UserWarning
-        If `V` is not a `~astropy.units.Quantity`, then a `UserWarning`
-        will be raised and units of meters per second will be assumed.
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
 
     Notes
     -----
diff --git a/plasmapy/physics/transport/collisions.py b/plasmapy/physics/transport/collisions.py
index 41fc97e0..de6f35fc 100644
--- a/plasmapy/physics/transport/collisions.py
+++ b/plasmapy/physics/transport/collisions.py
@@ -78,16 +78,20 @@ def Coulomb_logarithm(T,
     UnitConversionError
         If the units on any of the inputs are incorrect.
 
-    UserWarning
-        If the input velocity is greater than 80% of the speed of
-        light.
-
-    TypeError
         If the n_e, T, or V are not Quantities.
 
     PhysicsError
         If the result is smaller than 1.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The classical Coulomb logarithm is given by
@@ -303,13 +307,18 @@ def b_perp(T,
     UnitConversionError
         If the units on any of the inputs are incorrect
 
-    UserWarning
-        If the inputted velocity is greater than 80% of the speed of
-        light.
-
     TypeError
         If T, or V are not Quantities.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The distance of closest approach, b_perp, is given by [1]_
@@ -341,8 +350,7 @@ def b_perp(T,
     # classical effects dominate.
     # !!!Note: an average ionization parameter will have to be
     # included here in the future
-    bPerp = (charges[0] * charges[1] /
-             (4 * pi * eps0 * reduced_mass * V ** 2))
+    bPerp = (charges[0] * charges[1] / (4 * pi * eps0 * reduced_mass * V ** 2))
     return bPerp.to(u.m)
 
 
@@ -403,13 +411,18 @@ def impact_parameter(T,
     UnitConversionError
         If the units on any of the inputs are incorrect
 
-    UserWarning
-        If the inputted velocity is greater than 80% of the speed of
-        light.
-
     TypeError
         If the n_e, T, or V are not Quantities.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The minimum and maximum impact parameters may be calculated in a
@@ -588,13 +601,18 @@ def collision_frequency(T,
     UnitConversionError
         If the units on any of the inputs are incorrect
 
-    UserWarning
-        If the inputted velocity is greater than 80% of the speed of
-        light.
-
     TypeError
         If the n_e, T, or V are not Quantities.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The collision frequency is given by [1]_
@@ -745,13 +763,18 @@ def mean_free_path(T,
     UnitConversionError
         If the units on any of the inputs are incorrect
 
-    UserWarning
-        If the inputted velocity is greater than 80% of the speed of
-        light.
-
     TypeError
         If the n_e, T, or V are not Quantities.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The collisional mean free path is given by [1]_
@@ -854,13 +877,18 @@ def Spitzer_resistivity(T,
     UnitConversionError
         If the units on any of the inputs are incorrect
 
-    UserWarning
-        If the inputted velocity is greater than 80% of the speed of
-        light.
-
     TypeError
         If the n_e, T, or V are not Quantities.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The Spitzer resistivity is given by [1]_ [2]_
@@ -972,13 +1000,18 @@ def mobility(T,
     UnitConversionError
         If the units on any of the inputs are incorrect
 
-    UserWarning
-        If the inputted velocity is greater than 80% of the speed of
-        light.
-
     TypeError
         If the n_e, T, or V are not Quantities.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The mobility is given by [1]_
@@ -1088,13 +1121,18 @@ def Knudsen_number(characteristic_length,
     UnitConversionError
         If the units on any of the inputs are incorrect
 
-    UserWarning
-        If the inputted velocity is greater than 80% of the speed of
-        light.
-
     TypeError
         If the n_e, T, or V are not Quantities.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The Knudsen number is given by [1]_
@@ -1197,13 +1235,18 @@ def coupling_parameter(T,
     UnitConversionError
         If the units on any of the inputs are incorrect
 
-    UserWarning
-        If the inputted velocity is greater than 80% of the speed of
-        light.
-
     TypeError
         If the n_e, T, or V are not Quantities.
 
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed
+
+    ~plasmapy.utils.RelativityWarning
+        If the input velocity is greater than 5% of the speed of
+        light.
+
     Notes
     -----
     The coupling parameter is given by
diff --git a/plasmapy/utils/checks.py b/plasmapy/utils/checks.py
index a25b4a50..4bb14b0b 100644
--- a/plasmapy/utils/checks.py
+++ b/plasmapy/utils/checks.py
@@ -3,9 +3,11 @@
 
 import numpy as np
 from astropy import units as u
+from astropy.units import UnitsWarning
 from plasmapy.constants import c
 import warnings
 from plasmapy.utils.exceptions import RelativityWarning, RelativityError
+from textwrap import dedent
 
 
 def check_quantity(validations):
@@ -86,94 +88,26 @@ def wrapper(*args, **kwargs):
             for param_to_check, validation_settings in validations.items():
                 value_to_check = given_params_values[param_to_check]
 
-                can_be_negative = validation_settings.get(
-                    'can_be_negative', True)
-                can_be_complex = validation_settings.get(
-                    'can_be_complex', False)
-                can_be_inf = validation_settings.get(
-                    'can_be_inf', True)
-                can_be_nan = validation_settings.get(
-                    'can_be_nan', False)
-
-                _check_quantity(value_to_check,
-                                param_to_check,
-                                fname,
-                                validation_settings['units'],
-                                can_be_negative=can_be_negative,
-                                can_be_complex=can_be_complex,
-                                can_be_inf=can_be_inf,
-                                can_be_nan=can_be_nan)
-
-            return f(*args, **kwargs)
+                can_be_negative = validation_settings.get('can_be_negative', True)
+                can_be_complex = validation_settings.get('can_be_complex', False)
+                can_be_inf = validation_settings.get('can_be_inf', True)
+                can_be_nan = validation_settings.get('can_be_nan', False)
+
+                validated_value = _check_quantity(value_to_check,
+                                                  param_to_check,
+                                                  fname,
+                                                  validation_settings['units'],
+                                                  can_be_negative=can_be_negative,
+                                                  can_be_complex=can_be_complex,
+                                                  can_be_inf=can_be_inf,
+                                                  can_be_nan=can_be_nan)
+                given_params_values[param_to_check] = validated_value
+
+            return f(**given_params_values)
         return wrapper
     return decorator
 
 
-def check_relativistic(func=None, betafrac=0.1):
-    r"""
-    Warns or raises an exception when the output of the decorated
-    function is greater than `betafrac` times the speed of light.
-
-    Parameters
-    ----------
-    func : `function`, optional
-        The function to decorate.
-
-    betafrac : float, optional
-        The minimum fraction of the speed of light that will raise a
-        `~plasmapy.utils.RelativityWarning`. Defaults to 0.1.
-
-    Returns
-    -------
-    function
-        Decorated function.
-
-    Raises
-    ------
-    TypeError
-        If `V` is not a `~astropy.units.Quantity`.
-
-    ~astropy.units.UnitConversionError
-        If `V` is not in units of velocity.
-
-    ValueError
-        If `V` contains any `~numpy.nan` values.
-
-    ~plasmapy.utils.RelativityError
-        If `V` is greater than or equal to the speed of light.
-
-    Warns
-    -----
-    ~plasmapy.utils.RelativityWarning
-        If `V` is greater than or equal to `betafrac` times the speed of light,
-        but less than the speed of light.
-
-    Examples
-    --------
-    >>> from astropy import units as u
-    >>> @check_relativistic
-    ... def speed():
-    ...     return 1 * u.m / u.s
-
-    Passing in a custom `betafrac`:
-
-    >>> @check_relativistic(betafrac=0.01)
-    ... def speed():
-    ...     return 1 * u.m / u.s
-
-    """
-    def decorator(f):
-        @functools.wraps(f)
-        def wrapper(*args, **kwargs):
-            return_ = f(*args, **kwargs)
-            _check_relativistic(return_, f.__name__, betafrac=betafrac)
-            return return_
-        return wrapper
-    if func:
-        return decorator(func)
-    return decorator
-
-
 def _check_quantity(arg, argname, funcname, units, can_be_negative=True,
                     can_be_complex=False, can_be_inf=True, can_be_nan=False):
     """
@@ -229,15 +163,18 @@ def _check_quantity(arg, argname, funcname, units, can_be_negative=True,
 
     Warns
     -----
-    UserWarning
+    ~astropy.units.UnitsWarning
         If a `~astropy.units.Quantity` is not provided and unique units
-        are provided, a `UserWarning` will be raised and the inputted
+        are provided, a `UnitsWarning` will be raised and the inputted
         units will be assumed.
 
     Examples
     --------
     >>> from astropy import units as u
     >>> _check_quantity(4*u.T, 'B', 'f', u.T)
+    <Quantity 4. T>
+    >>> _check_quantity(4, 'B', 'f', u.T)
+    <Quantity 4. T>
 
     """
 
@@ -272,6 +209,13 @@ def _check_quantity(arg, argname, funcname, units, can_be_negative=True,
 
     # Make sure arg is a quantity with correct units
 
+    unit_casting_warning = dedent(
+            f"""No units are specified for {argname} = {arg} in {funcname}. Assuming units of {str(units[0])}.
+                To silence this warning, explicitly pass in an Astropy Quantity (from astropy.units)
+                (see http://docs.astropy.org/en/stable/units/)""")
+
+    # TODO include explicit note on how to pass in Astropy Quantity
+
     if not isinstance(arg, (u.Quantity)):
         if len(units) != 1:
             raise TypeError(typeerror_message)
@@ -281,10 +225,7 @@ def _check_quantity(arg, argname, funcname, units, can_be_negative=True,
             except Exception:
                 raise TypeError(typeerror_message)
             else:
-                raise UserWarning(
-                    f"No units are specified for {argname} in {funcname}. "
-                    f"Assuming units of {str(units[0])}."
-                )
+                warnings.warn(UnitsWarning(unit_casting_warning))
     if not isinstance(arg, u.Quantity):
         raise u.UnitsError("{} is still not a Quantity after checks!".format(arg))
 
@@ -316,8 +257,75 @@ def _check_quantity(arg, argname, funcname, units, can_be_negative=True,
     elif not can_be_inf and np.any(np.isinf(arg.value)):
         raise ValueError(f"{valueerror_message} infs.")
 
+    return arg
 
-def _check_relativistic(V, funcname, betafrac=0.1):
+
+def check_relativistic(func=None, betafrac=0.05):
+    r"""
+    Warns or raises an exception when the output of the decorated
+    function is greater than `betafrac` times the speed of light.
+
+    Parameters
+    ----------
+    func : `function`, optional
+        The function to decorate.
+
+    betafrac : float, optional
+        The minimum fraction of the speed of light that will raise a
+        `~plasmapy.utils.RelativityWarning`. Defaults to 5%.
+
+    Returns
+    -------
+    function
+        Decorated function.
+
+    Raises
+    ------
+    TypeError
+        If `V` is not a `~astropy.units.Quantity`.
+
+    ~astropy.units.UnitConversionError
+        If `V` is not in units of velocity.
+
+    ValueError
+        If `V` contains any `~numpy.nan` values.
+
+    ~plasmapy.utils.RelativityError
+        If `V` is greater than or equal to the speed of light.
+
+    Warns
+    -----
+    ~plasmapy.utils.RelativityWarning
+        If `V` is greater than or equal to `betafrac` times the speed of light,
+        but less than the speed of light.
+
+    Examples
+    --------
+    >>> from astropy import units as u
+    >>> @check_relativistic
+    ... def speed():
+    ...     return 1 * u.m / u.s
+
+    Passing in a custom `betafrac`:
+
+    >>> @check_relativistic(betafrac=0.01)
+    ... def speed():
+    ...     return 1 * u.m / u.s
+
+    """
+    def decorator(f):
+        @functools.wraps(f)
+        def wrapper(*args, **kwargs):
+            return_ = f(*args, **kwargs)
+            _check_relativistic(return_, f.__name__, betafrac=betafrac)
+            return return_
+        return wrapper
+    if func:
+        return decorator(func)
+    return decorator
+
+
+def _check_relativistic(V, funcname, betafrac=0.05):
     r"""
     Warn or raise error for relativistic or superrelativistic
     velocities.
@@ -331,9 +339,9 @@ def _check_relativistic(V, funcname, betafrac=0.1):
         The name of the original function to be printed in the error
         messages.
 
-    betafrac : float
+    betafrac : float, optional
         The minimum fraction of the speed of light that will generate
-        a warning.
+        a warning. Defaults to 5%.
 
     Raises
     ------


Test patch:
diff --git a/plasmapy/physics/tests/test_parameters.py b/plasmapy/physics/tests/test_parameters.py
index 7b010549..227dc69b 100644
--- a/plasmapy/physics/tests/test_parameters.py
+++ b/plasmapy/physics/tests/test_parameters.py
@@ -148,7 +148,7 @@ def test_Alfven_speed():
         assert Alfven_speed(-np.inf * u.T, 1 * u.m ** -3,
                             ion='p') == np.inf * u.m / u.s
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert Alfven_speed(1.0, n_i) == Alfven_speed(1.0 * u.T, n_i)
 
     Alfven_speed(1 * u.T, 5e19 * u.m ** -3, ion='p')
@@ -234,11 +234,11 @@ def test_ion_sound_speed():
     with pytest.raises(ValueError):
         ion_sound_speed(T_e=T_negarr, T_i=0 * u.K)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert ion_sound_speed(T_e=1.2e6, T_i=0 * u.K) == ion_sound_speed(T_e=1.2e6 * u.K,
                                                                           T_i=0 * u.K)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert ion_sound_speed(T_i=1.3e6, T_e=0 * u.K) == ion_sound_speed(T_i=1.3e6 * u.K,
                                                                           T_e=0 * u.K)
 
@@ -276,7 +276,7 @@ def test_thermal_speed():
     with pytest.raises(RelativityError):
         thermal_speed(5e19 * u.K)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert thermal_speed(1e5) == thermal_speed(1e5 * u.K)
 
     assert thermal_speed(T_i, particle='p').unit.is_equivalent(u.m / u.s)
@@ -306,7 +306,7 @@ def test_thermal_speed():
     with pytest.raises(ValueError):
         thermal_speed(T_i, particle='asdfasd')
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert thermal_speed(1e6, particle='p') == thermal_speed(1e6 * u.K, particle='p')
 
     assert np.isclose(thermal_speed(1e6 * u.K,
@@ -438,7 +438,7 @@ def test_gyrofrequency():
     f_ce_use_equiv = omega_ce.to(u.Hz, equivalencies=[(u.cy / u.s, u.Hz)])
     assert np.isclose(f_ce.value, f_ce_use_equiv.value)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert gyrofrequency(5.0) == gyrofrequency(5.0 * u.T)
 
     assert gyrofrequency(B, particle=ion).unit.is_equivalent(u.rad / u.s)
@@ -459,7 +459,7 @@ def test_gyrofrequency():
 
     assert gyrofrequency(B, particle='e+') == gyrofrequency(B)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         gyrofrequency(8, 'p')
 
     with pytest.raises(u.UnitConversionError):
@@ -468,7 +468,7 @@ def test_gyrofrequency():
     with pytest.raises(InvalidParticleError):
         gyrofrequency(8 * u.T, particle='asdfasd')
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         # TODO this should be WARNS, not RAISES. and it's probably still raised
         assert gyrofrequency(5.0, 'p') == gyrofrequency(5.0 * u.T, 'p')
 
@@ -514,10 +514,10 @@ def test_gyroradius():
     with pytest.raises(ValueError):
         gyroradius(3.14159 * u.T, T_i=-1 * u.K)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert gyroradius(1.0, Vperp=1.0) == gyroradius(1.0 * u.T, Vperp=1.0 * u.m / u.s)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert gyroradius(1.1, T_i=1.2) == gyroradius(1.1 * u.T, T_i=1.2 * u.K)
 
     with pytest.raises(ValueError):
@@ -564,12 +564,12 @@ def test_gyroradius():
     with pytest.raises(ValueError):
         gyroradius(B, particle='p', T_i=-1 * u.K)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         gyro_without_units = gyroradius(1.0, particle="p", Vperp=1.0)
         gyro_with_units = gyroradius(1.0 * u.T, particle="p", Vperp=1.0 * u.m / u.s)
         assert gyro_without_units == gyro_with_units
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         gyro_t_without_units = gyroradius(1.1, particle="p", T_i=1.2)
         gyro_t_with_units = gyroradius(1.1 * u.T, particle="p", T_i=1.2 * u.K)
         assert gyro_t_with_units == gyro_t_without_units
@@ -600,7 +600,7 @@ def test_plasma_frequency():
     with pytest.raises(ValueError):
         plasma_frequency(np.nan * u.m ** -3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert plasma_frequency(1e19) == plasma_frequency(1e19 * u.m ** -3)
 
         assert plasma_frequency(n_i, particle='p').unit.is_equivalent(u.rad / u.s)
@@ -614,7 +614,7 @@ def test_plasma_frequency():
     with pytest.raises(ValueError):
         plasma_frequency(n=5 * u.m ** -3, particle='sdfas')
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         plasma_freq_no_units = plasma_frequency(1e19, particle='p')
         assert plasma_freq_no_units == plasma_frequency(1e19 * u.m ** -3, particle='p')
 
@@ -639,7 +639,7 @@ def test_Debye_length():
     assert np.isclose(Debye_length(
         1 * u.eV, 1 * u.cm ** -3).value, 7.43, atol=0.005)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         Debye_length(5, 5 * u.m ** -3)
 
     with pytest.raises(u.UnitConversionError):
@@ -656,10 +656,10 @@ def test_Debye_length():
     with pytest.raises(ValueError):
         Debye_length(Tarr2, narr3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert Debye_length(2.0, 2.0) == Debye_length(2.0 * u.K, 2.0 * u.m ** -3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert Debye_length(2.0 * u.K, 2.0) == Debye_length(2.0, 2.0 * u.m ** -3)
 
 
@@ -674,7 +674,7 @@ def test_Debye_number():
 
     assert np.isclose(Debye_number(1 * u.eV, 1 * u.cm ** -3).value, 1720862385.43342)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         Debye_number(T_e, 4)
 
     with pytest.raises(TypeError):
@@ -694,10 +694,10 @@ def test_Debye_number():
     with pytest.raises(ValueError):
         Debye_number(Tarr2, narr3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert Debye_number(1.1, 1.1) == Debye_number(1.1 * u.K, 1.1 * u.m ** -3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert Debye_number(1.1 * u.K, 1.1) == Debye_number(1.1, 1.1 * u.m ** -3)
 
 
@@ -714,7 +714,7 @@ def test_inertial_length():
 
     assert inertial_length(n_i, particle='p') == inertial_length(n_i, particle='p')
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         inertial_length(4, particle='p')
 
     with pytest.raises(u.UnitConversionError):
@@ -726,7 +726,7 @@ def test_inertial_length():
     with pytest.raises(ValueError):
         inertial_length(n_i, particle=-135)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         inertial_length_no_units = inertial_length(1e19, particle='p')
         assert inertial_length_no_units == inertial_length(1e19 * u.m ** -3, particle='p')
 
@@ -734,7 +734,7 @@ def test_inertial_length():
 
     assert np.isclose(inertial_length(1 * u.cm ** -3).cgs.value, 5.31e5, rtol=1e-3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         inertial_length(5)
 
     with pytest.raises(u.UnitConversionError):
@@ -743,7 +743,7 @@ def test_inertial_length():
     with pytest.raises(ValueError):
         inertial_length(-5 * u.m ** -3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert inertial_length(1e19) == inertial_length(1e19 * u.m ** -3)
 
 
@@ -762,7 +762,7 @@ def test_magnetic_pressure():
 
     assert np.isclose(magnetic_pressure(B).value, 397887.35772973835)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         magnetic_pressure(5)
 
     with pytest.raises(u.UnitConversionError):
@@ -777,7 +777,7 @@ def test_magnetic_pressure():
     with pytest.raises(ValueError):
         magnetic_pressure(B_nanarr)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert magnetic_pressure(22.2) == magnetic_pressure(22.2 * u.T)
 
 
@@ -800,7 +800,7 @@ def test_magnetic_energy_density():
 
     assert magnetic_energy_density(B_arr)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         magnetic_energy_density(5)
 
     with pytest.raises(u.UnitConversionError):
@@ -815,7 +815,7 @@ def test_magnetic_energy_density():
     with pytest.raises(ValueError):
         magnetic_energy_density(B_nanarr)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert magnetic_energy_density(22.2) == magnetic_energy_density(22.2 * u.T)
 
 
@@ -835,11 +835,11 @@ def test_upper_hybrid_frequency():
     with pytest.raises(ValueError):
         upper_hybrid_frequency(5 * u.T, n_e=-1 * u.m ** -3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert upper_hybrid_frequency(1.2, 1.3) == upper_hybrid_frequency(1.2 * u.T,
                                                                           1.3 * u.m ** -3)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert upper_hybrid_frequency(1.4 * u.T, 1.3) == upper_hybrid_frequency(1.4,
                                                                                 1.3 * u.m ** -3)
 
@@ -870,6 +870,6 @@ def test_lower_hybrid_frequency():
         lower_hybrid_frequency(
             np.nan * u.T, n_i=-5e19 * u.m ** -3, ion='asdfasd')
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         assert lower_hybrid_frequency(1.3, 1e19) == lower_hybrid_frequency(1.3 * u.T,
                                                                            1e19 * u.m ** -3)
diff --git a/plasmapy/physics/tests/test_quantum.py b/plasmapy/physics/tests/test_quantum.py
index 0c264fe0..ea0ecd9f 100644
--- a/plasmapy/physics/tests/test_quantum.py
+++ b/plasmapy/physics/tests/test_quantum.py
@@ -47,7 +47,7 @@ def test_deBroglie_wavelength():
     with pytest.raises(RelativityError):
         deBroglie_wavelength(c * 1.000000001, 'e')
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         deBroglie_wavelength(0.79450719277, 'Be-7 1+')
 
     with pytest.raises(u.UnitConversionError):
diff --git a/plasmapy/physics/tests/test_relativity.py b/plasmapy/physics/tests/test_relativity.py
index d4df1c74..2b47ad50 100644
--- a/plasmapy/physics/tests/test_relativity.py
+++ b/plasmapy/physics/tests/test_relativity.py
@@ -29,10 +29,10 @@ def test_Lorentz_factor():
     with pytest.raises(RelativityError):
         Lorentz_factor(1.0000000001*c)
 
-    with pytest.raises((ValueError, UserWarning)):
+    with pytest.raises(ValueError):
         Lorentz_factor(299792459)
 
-    with pytest.raises(UserWarning):
+    with pytest.warns(u.UnitsWarning):
         Lorentz_factor(2.2)
 
     with pytest.raises(u.UnitConversionError):
diff --git a/plasmapy/utils/tests/test_checks.py b/plasmapy/utils/tests/test_checks.py
index 4dda9e29..7b9482a2 100644
--- a/plasmapy/utils/tests/test_checks.py
+++ b/plasmapy/utils/tests/test_checks.py
@@ -20,7 +20,6 @@
     (5 * u.T, [u.T, 1], TypeError),
     (5 * u.T, [1, u.m], TypeError),
     (u.T, u.J, TypeError),
-    (5.0, u.m, UserWarning),
     (3 * u.m / u.s, u.m, u.UnitConversionError),
     (5j * u.K, u.K, ValueError),
 ]
@@ -66,6 +65,10 @@ def test__check_quantity_errors_non_default(
                         can_be_inf=can_be_inf)
 
 
+def test__check_quantity_warns_on_casting():
+    with pytest.warns(u.UnitsWarning):
+        _check_quantity(5, 'arg', 'funcname', u.m,)
+
 @pytest.mark.parametrize(
     "value, units, error", quantity_error_examples_default)
 def test__check_quantity_errors_default(value, units, error):