Resolutions

Resolutions provide an expected answer to questions. They are the second half of test assertions in ScreenPy: the “expected value”. (The first half are Questions, if you missed that page.)

Using Resolutions

Like Questions, you probably will not use a resolution directly. You will typically pass a resolution along with a question into your actor’s should_see_the() method:

from screenpy.questions import Text
from screenpy.resolutions import ReadsExactly

from ..user_interface.homepage import WELCOME_MESSAGE

Perry.should_see_the((Text.of_the(WELCOME_MESSAGE), ReadsExactly("Welcome!")))

In that line of code, ReadsExactly is returning a PyHamcrest matcher. It will be evaluated later as should_see_the() does its job. If the expected value (“Welcome!”) matches the actual value retrieved by our question, bravo! Our test passes. If they do not match, boo! Our test fails.

Writing New Resolutions

Resolutions are really just an abstraction barrier for the truly excellent PyHamcrest library. To add your own resolutions, create your resolution class by inheriting from the BaseResolution class. All you need to provide in your resolution is a line class property, which is just a human readable string for the log, and then to define the __init__ method.

The custom Resolution’s __init__ method will need to set the expected value, and instantiate the PyHamcrest matcher that your resolution is masking. For several examples, see the documentation of the Provided Resolutions below.

Provided Resolutions

ContainsTheText

class screenpy.resolutions.ContainsTheText(substring: str)

Matches a substring (e.g. “play” in “screenplay”).

IsEmpty

class screenpy.resolutions.IsEmpty

Matches on an empty collection (e.g. []).

IsEqualTo

class screenpy.resolutions.IsEqualTo(obj: object)

Matches on equality (i.e. a == b).

IsNot

class screenpy.resolutions.IsNot(resolution: Any)

Matches a negated Resolution (e.g. not ReadsExactly(“yes”)).

ReadsExactly

class screenpy.resolutions.ReadsExactly(string: str)

Matches a string exactly (e.g. “screenplay” == “screenplay”).