Skip to content

Conversation

Bastian-Krause
Copy link
Member

Description
pytest allows setting markers via function decorators [1], class decorators [2] and "pytestmark" global to mark whole modules [2]. Additionally, each of these variants can specify multiple markers.

labgrid's pytest plugin considered only the closest marker. Change that to allow combinations of multiple markers.

This allows use cases like:

import pytest

pytestmark = pytest.mark.lg_feature("watchdog")

@pytest.mark.lg_feature("barebox")
def test_watchdog_barebox(barebox):
    ..

Tests in this module are only run if the feature flag "watchdog" is available. The specific test "test_watchdog_barebox" is only run if the feature flag "barebox" is available additionally.

[1] https://docs.pytest.org/en/latest/example/markers.html#adding-a-custom-marker-from-a-plugin
[2] https://docs.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules

Checklist

  • Tests for the feature
  • CHANGES.rst has been updated
  • PR has been tested

…ction_modifyitems

have_feature is set a few lines below without consideration of its
previous value, so drop this statement.

Signed-off-by: Bastian Krause <[email protected]>
…erwriting previous ones

pytest allows setting markers via function decorators [1], class
decorators [2] and "pytestmark" global to mark whole modules [2].
Additionally, each of these variants can specify multiple markers.

labgrid's pytest plugin considered only the closest marker. Change that
to allow combinations of multiple markers.

This allows use cases like:

  import pytest

  pytestmark = pytest.mark.lg_feature("watchdog")

  @pytest.mark.lg_feature("barebox")
  def test_watchdog_barebox(barebox):
      ..

Tests in this module are only run if the feature flag "watchdog" is
available. The specific test "test_watchdog_barebox" is only run if the
feature flag "barebox" is available additionally.

[1] https://docs.pytest.org/en/latest/example/markers.html#adding-a-custom-marker-from-a-plugin
[2] https://docs.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules

Signed-off-by: Bastian Krause <[email protected]>
@codecov
Copy link

codecov bot commented Oct 29, 2021

Codecov Report

Merging #861 (5dc0330) into master (3fe80b0) will decrease coverage by 0.0%.
The diff coverage is 87.5%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #861     +/-   ##
========================================
- Coverage    56.9%   56.9%   -0.1%     
========================================
  Files         145     145             
  Lines       10861   10859      -2     
========================================
- Hits         6182    6180      -2     
  Misses       4679    4679             
Impacted Files Coverage Δ
labgrid/pytestplugin/hooks.py 93.5% <87.5%> (-0.3%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3fe80b0...5dc0330. Read the comment docs.

@Bastian-Krause Bastian-Krause changed the title combine multiple lg_feature markers instead of overwriting previous ones combine multiple lg_feature markers instead of considering only closest one Nov 1, 2021
@Emantor Emantor merged commit bd0ede7 into labgrid-project:master Nov 1, 2021
@Bastian-Krause Bastian-Krause deleted the bst/multi-feature-flags branch January 15, 2022 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants