Skip to content

Commit

Permalink
Markers parsing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare committed Dec 11, 2023
1 parent cce8cf2 commit 6bdf021
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tests/data/test_sample.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# encoding=utf-8
"""Sample test module."""
import unittest
import pytest


pytestmark = [pytest.mark.run_in_one_thread, pytest.mark.tier1]

CONSTANT = 'contant-value'


Expand Down Expand Up @@ -72,3 +75,14 @@ def test_method(self):

def test_without_docstring(self): # noqa: D102
pass


@pytest.mark.on_prem_provisioning
class TestclasswithMarkers:
"""Class to verify tests markers are collected from class."""

@pytest.mark.skipif(2 == 3, reason='2 is not 3')
@pytest.mark.osp
def test_markers_sample(self):
"""Test for markers at test level."""
assert True
4 changes: 2 additions & 2 deletions tests/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_collect_tests(path):
"""Check if ``collect_tests`` 'tests/data'collect tests."""
tests = collector.collect_tests(path)
assert 'tests/data/test_sample.py' in tests
assert len(tests['tests/data/test_sample.py']) == 4
assert len(tests['tests/data/test_sample.py']) == 5

# Check if we are not doing a specific python module collection
if path.endswith('.py'):
Expand All @@ -30,7 +30,7 @@ def test_collect_ignore_path(ignore_path):
tests = collector.collect_tests('tests/data', [ignore_path])
assert 'tests/data/ignore_dir/test_ignore_dir.py' not in tests
assert 'tests/data/test_sample.py' in tests
assert len(tests['tests/data/test_sample.py']) == 4
assert len(tests['tests/data/test_sample.py']) == 5


@pytest.mark.parametrize('filename', ('test_module.py', 'module_test.py'))
Expand Down
24 changes: 24 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,27 @@ def test_parse_rst_special_characters():
u'<p>String with special character like é</p>\n'
u'</main>\n'
)


def test_parse_markers():
"""
Test if the markers list is parsed.
List should be comma separated list of markers from all levels after
removing 'pytest.mark' text and ignore some markers.
"""
_mod_markers = ['pytest.mark.e2e', 'pytest.mark.destructive']
_class_markers = [
'pytest.mark.on_prem_provisioning',
"pytest.mark.usefixtures('cleandir')"
]
_test_markers = [
"pytest.mark.parametrize('something', ['a', 'b'])",
'pytest.mark.skipif(not settings.robottelo.REPOS_HOSTING_URL)',
'pytest.mark.tier1'
]
_all_markers = [_mod_markers, _class_markers, _test_markers]

expected = 'e2e, destructive, on_prem_provisioning, tier1'

assert parser.parse_markers(_all_markers) == expected
11 changes: 11 additions & 0 deletions tests/test_source_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,14 @@ def test_source_generator():
'(lambda v: (v if v else None))'
')',
]


def test_source_markers():
"""Verifies if the test collection collects test markers."""
tests = collector.collect_tests('tests/data/test_sample.py')
marked_test = [
test for test in tests['tests/data/test_sample.py']
if test.name == 'test_markers_sample'
].pop()
assert marked_test.fields['markers'] == ('run_in_one_thread, tier1, '
'on_prem_provisioning, osp')

0 comments on commit 6bdf021

Please sign in to comment.