Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the filter by dynamic case/tag issue #607

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/pabot/pabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,13 +1197,16 @@ def generate_suite_names_with_builder(outs_dir, datasources, options):
)

suite = builder.build(*datasources)
settings.rpa = builder.rpa
suite.configure(**settings.suite_config)

if settings.pre_run_modifiers:
_write.error = _write.warn = _write.info = _write.debug = _write.trace = _write
suite.visit(
ModelModifier(settings.pre_run_modifiers, settings.run_empty_suite, _write)
)

settings.rpa = builder.rpa
suite.configure(**settings.suite_config)

all_suites = (
get_all_suites_from_main_suite(suite.suites) if suite.suites else [suite]
)
Expand Down
92 changes: 92 additions & 0 deletions tests/test_prerunmodifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import unittest
import tempfile
import textwrap
import shutil
import subprocess
import sys


class PrerunModifierTests(unittest.TestCase):
@classmethod
def setUpClass(self):
self.tmpdir = tempfile.mkdtemp()

# robot case file
self.robot_file_path = f'{self.tmpdir}/test.robot'
with open(self.robot_file_path, 'w') as robot_file:
robot_file.write(
textwrap.dedent("""
*** Test Cases ***
Testing 1
[Tags] tag
Log hello

Testing 2
[Tags] tag
Log world
"""))

# prerunmodifier script
self.modifier_file_path = f'{self.tmpdir}/Modifier.py'
with open(self.modifier_file_path, 'w') as modifier_file:
modifier_file.write(
textwrap.dedent("""
from robot.api import SuiteVisitor


class Modifier(SuiteVisitor):
def start_suite(self, suite):
if suite.tests:
for test in suite.tests:
if '1' in test.name:
name = 'new-name-1'
tag = 'tag1'
else:
name = 'new-name-2'
tag = 'tag2'
test.name = name
test.tags.add([tag])
"""))

def test_pre_run_with_new_tag(self):
process = subprocess.Popen(
[
sys.executable,
"-m", "pabot.pabot",
"--prerunmodifier",
self.modifier_file_path,
"--include",
"tag2",
self.robot_file_path
],
cwd=self.tmpdir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)

stdout, stderr = process.communicate()
self.assertIn(b'1 tests, 1 passed, 0 failed, 0 skipped.', stdout)

def test_pre_run_with_new_name(self):
process = subprocess.Popen(
[
sys.executable,
"-m", "pabot.pabot",
"--prerunmodifier",
self.modifier_file_path,
"--test",
"new-name-1",
self.robot_file_path
],
cwd=self.tmpdir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)

stdout, stderr = process.communicate()
self.assertIn(b'1 tests, 1 passed, 0 failed, 0 skipped.', stdout)

@classmethod
def tearDownClass(self):
shutil.rmtree(self.tmpdir)

Loading