since skipping an individual test method or function based on certain conditional is one of the most common uses of test skippingpy test provides convenience decorator that allows us to do this in one line the decorator accepts single stringwhich can contain any executable python code that evaluates to boolean value for examplethe following test will only run on python or higherimport py test @py test mark skipif("sys version_info <( , )"def test_python ()assert "hellodecode(="hellothe py test mark xfail decorator behaves similarlyexcept that it marks test as expected to failsimilar to unittest expectedfailure(if the test is successfulit will be recorded as failureif it failsit will be reported as expected behavior in the case of xfailthe conditional argument is optionalif it is not suppliedthe test will be marked as expected to fail under all conditions imitating expensive objects sometimeswe want to test code that requires an object be supplied that is either expensive or difficult to construct while this may mean your api needs rethinking to have more testable interface (which typically means more usable interface)we sometimes find ourselves writing test code that has ton of boilerplate to set up objects that are only incidentally related to the code under test for exampleimagine we have some code that keeps track of flight statuses in key-value store (such as redis or memcachesuch that we can store the timestamp and the most recent status basic version of such code might look like thisimport datetime import redis class flightstatustrackerallowed_statuses {'cancelled''delayed''on time'def __init__(self)self redis redis strictredis(def change_status(selfflightstatus)