Skip to content

Commit

Permalink
Merge pull request #607 from wendi616/main
Browse files Browse the repository at this point in the history
fix the filter by dynamic case/tag issue
  • Loading branch information
mkorpela authored Dec 8, 2024
2 parents 3c1fbe8 + 3ff8f54 commit fba342b
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
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)

0 comments on commit fba342b

Please sign in to comment.