Skip to content

Commit 5ad2747

Browse files
Fix for issue with loading step impls from relative dirs (#430)
* Updating check for relative paths Signed-off-by: Kunal Vishwasrao <[email protected]> * Added unit test scenario with '..' in between path Signed-off-by: Kunal Vishwasrao <[email protected]> * Added proper comment to the relative file path check Signed-off-by: Kunal Vishwasrao <[email protected]> * Bump version Signed-off-by: Chad Wilson <[email protected]> --------- Signed-off-by: Kunal Vishwasrao <[email protected]> Signed-off-by: Chad Wilson <[email protected]> Co-authored-by: Chad Wilson <[email protected]>
1 parent 0c477c8 commit 5ad2747

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

getgauge/impl_loader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def _import_file(base_dir, file_path):
9898
# Inject instance in each class method (hook/step)
9999
def update_step_registry_with_class(instance, file_path):
100100
# Resolve the absolute path from relative path
101-
file_path = os.path.abspath(file_path) if str(file_path).startswith("..") else file_path
101+
# Note: relative path syntax ".." can appear in between the file_path too like "<Project_Root>/../../Other_Project/src/step_impl/file.py"
102+
file_path = os.path.abspath(file_path) if ".." in str(file_path) else file_path
102103
method_list = registry.get_all_methods_in(file_path)
103104
for info in method_list:
104105
class_methods = [x[0] for x in inspect.getmembers(instance, inspect.ismethod)]

python.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "python",
3-
"version": "0.4.8",
3+
"version": "0.4.9",
44
"description": "Python support for gauge",
55
"run": {
66
"windows": [

tests/test_impl_loader.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77

88
class ImplLoaderTest(unittest.TestCase):
99
def setUp(self):
10+
self.curr_dir = os.getcwd()
1011
self.relative_file_path = os.path.join('..', 'test_relative_import', 'relative_import_class.py')
12+
self.relative_file_path_one_level_above = os.path.join('tests', '..', 'test_relative_import', 'relative_import_class.py')
1113

1214
def test_update_step_registry_with_class(self):
13-
curr_dir = os.getcwd()
1415
os.chdir('tests')
1516
method_list = update_step_registry_with_class(Sample(), self.relative_file_path)
16-
os.chdir(curr_dir)
17+
os.chdir(self.curr_dir)
18+
self.assertEqual(["Greet <name> from inside the class",
19+
"Greet <name> from outside the class"],
20+
[method.step_text for method in method_list])
21+
22+
def test_update_step_registry_with_class_one_level_above(self):
23+
os.chdir(self.curr_dir)
24+
method_list = update_step_registry_with_class(Sample(), self.relative_file_path_one_level_above)
1725
self.assertEqual(["Greet <name> from inside the class",
1826
"Greet <name> from outside the class"],
1927
[method.step_text for method in method_list])

0 commit comments

Comments
 (0)