Context?

What is a context?

A context object is the primary interface used inside testing tools.


Why should I care?

There are times where knowing about the context object can help you write better tests.


What does it do?

Tracks file name, line number, and other meta-data about the currently running tool. It is also the primary way to generate events.
Usage

Using the context

This is the most simple usage.
Rules

Context 10 commandments


These rules are very important. Failure to follow these rules will lead to incorrect events, diagnostics, extra warnings, exceptions, and possibly death.

  1. Get it as early as possible
  2. Release it as late as possible
  3. Do not forget to release the context
  4. Each sub should get its own
  5. Do not pass a context around
  6. Do not cache or store the context to use later
  7. Do not share a context
  8. Assumes it is obtained within a sub (not package scope)
  9. Do not alter the context internals
  10. Do not monkey-patch the context
Events

Event Generation

See the facets section above for more details on facets.
Legacy Events

Legacy Event Generation

The legacy event types all have a shortcut method that creates, sends, and returns an event: All other legacy/custom event types can be generated via send_event() and build_event()