Adds `when` param to `skip` and `xfail` decorators, allowing you to only apply them when some boolean or Callable predicate holds. e.g.
python
skip("Skipped on Windows", when=platform.system() == "Windows")
test("_build_package_name constructs package name '{pkg}' from '{path}'")
def _(
pkg=each("", "foo", "foo.bar"),
path=each("foo.py", "foo/bar.py", "foo/bar/baz.py"),
):
m = ModuleType(name="")
m.__file__ = path
assert _build_package_name(m) == pkg
skip("Skipped on Unix", when=platform.system() != "Windows")
test("_build_package_name constructs package name '{pkg}' from '{path}'")
def _(
pkg=each("", "foo", "foo.bar"),
path=each("foo.py", "foo\\bar.py", "foo\\bar\\baz.py"),
):
m = ModuleType(name="")
m.__file__ = path
assert _build_package_name(m) == pkg
When run on a non-Windows system:
<img width="1286" alt="image" src="https://user-images.githubusercontent.com/5740731/113418236-fd6f5a00-93bc-11eb-8b72-e3c5c2aa31e4.png">