Skip to content

Allow access to custom values in skip markers #7712

@bluetech

Description

@bluetech

This issue discusses the feature request presented in PR #7695.

Currently conditions in skip and xfail markers can have two forms:

  • A boolean (=> a regular Python expression evaluated normally during collection). Can only access global Python values.
  • A string of a Python expression. Evaluated during setup/call time. Has access to os, sys, platform, config.

The feature request is to be able to skip based on custom user values. Proposed solutions so far are:

  1. Use the boolean with global variables. This is not so nice because can't the lifecycle can't be controlled, and importing the necessary values add boilerplate.

  2. (PR Allow contibuting additional global variables for skipif/xfail #7695 by @s0undt3ch) Add a new hook pytest_markeval_namespace which can add new values to the os, sys... list above. Works only for string conditions.

  3. Add a new condition type, a callable, which is evaluated lazily. Allow this callable to take fixtures, as if requested by the item.

We agreed to try approach 3 (or another proposal) for pytest 6.2, but if we don't get to it, merge approach 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: marksrelated to marks, either the general marks or builtintype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions