Repository: mkorpela/pabot

Issue:
Pabt cannot be filtered by dynamic casename or tage which are generated by prerunmodifier script
As the title, user can change the some of atrributes of the suite or case ,  in that case, if we try to filter with the modifier value by -t or -i, the pabot will get nothing, but it works in robot scenario.

Pabot Version: 4.0.4
Robot Version: 7.0.1

robot scenario:
`$ robot --prerunmodifier Modifier.py -i tag2 .
==============================================================================
Test Prerun
==============================================================================
Test Prerun.Test
==============================================================================
new-name-2                                                            | PASS |
------------------------------------------------------------------------------
Test Prerun.Test                                                      | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Test Prerun                                                           | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Output:  C:\Dev\pabot_test\test_prerun\output.xml
Log:     C:\Dev\pabot_test\test_prerun\log.html
Report:  C:\Dev\pabot_test\test_prerun\report.html
`

Pabot scenario:
`$ pabot --prerunmodifier Modifier.py -i tag2 .
Suite 'Test Prerun' contains no tests matching tag 'tag2'.
Stopping PabotLib process
Robot Framework remote server at 127.0.0.1:8270 started.
Robot Framework remote server at 127.0.0.1:8270 stopped.
PabotLib process stopped
Total testing: 0.0 seconds
Elapsed time:  3.44 seconds`

The case and modifier script can be found in attachement.
[test_prerun.zip](https://github.com/user-attachments/files/18035600/test_prerun.zip)

Discussion:

Solution patch:
diff --git a/src/pabot/pabot.py b/src/pabot/pabot.py
index ebcdef10..e4dc36d1 100644
--- a/src/pabot/pabot.py
+++ b/src/pabot/pabot.py
@@ -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]
     )


Test patch:
diff --git a/tests/test_prerunmodifier.py b/tests/test_prerunmodifier.py
new file mode 100644
index 00000000..0825c491
--- /dev/null
+++ b/tests/test_prerunmodifier.py
@@ -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)
+        
\ No newline at end of file