-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #607 from wendi616/main
fix the filter by dynamic case/tag issue
- Loading branch information
Showing
2 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|