Repository navigation
Description
Description:
After merging #360 all the previous issues regarding relatively importing step implementations from another project were fixed but when I created step implementations inside a class in different project and tried use those steps inside specs by using the relative import feature, I am getting an error saying missing 1 required positional argument despite of having everything correctly present.
Gauge-Main-Project/step_impl/step_impl.py
from getgauge.python import step, Messages
class BaseMainClass:
def __init__(self) -> None:
pass
class MainClass(BaseMainClass):
@step("Greet <name> from Main Project")
def greet_main_project(self, name):
print(f"Hello from the Main Project, {name}")
Messages.write_message(f"Hello from the Main Project - {name}")
Gauge-Sub-Project/step_impl/step_impl.py
from getgauge.python import step, Messages
class BaseSubClass:
def __init__(self) -> None:
pass
class SubClass(BaseSubClass):
@step("Greet <name> from Sub Project")
def greet_sub_project(sub, name):
print(f"Hello from the Sub Project, {name}")
Messages.write_message(f"Hello from the Main Project - {name}")
Sample Spec File
# Test Relative Imports
> Sample spec from Sub Project
## Test Relative Imports From Class
* Greet "Kunal" from Sub Project
* Greet "Kunal" from Main Project
To Reproduce:
Steps (or project) to reproduce the behavior:
- Initialize 2 gauge projects with
gauge init pythoncommand - Update the
step_impl.pyfiles for both the projects like shown above - Setup the
Gauge-Sub-Project/env/default/python.propertiesfile like:STEP_IMPL_DIR = step_impl, ../Gauge-Main-Project/step_impl - Create a spec file with the above mentioned steps
- Run the spec
- See error
Logs
Traceback (most recent call last):
File "<PATH_TO_VENV>\Lib\site-packages\getgauge\executor.py", line 33, in execute_method
step.impl(*params)
TypeError: MainClass.greet_main_project() missing 1 required positional argument: 'name'
Possible Fix:
This issue arises because the update_step_resgistry_with_class() method inside the impl_loader.py file is unable to fetch all the methods inside that step implementation file inside get_all_methods_in() method due to the file_path being a relative file path.
Resolving this relative file path into an absolute file path fixes this issue.
Versions:
- OS -
Windows 10 (10.0.19045) - Python version -
3.11.4 - Gauge version -
1.6.7
Project Structure:
Project-Root
├── Gauge-Main-Project
│ ├── env
│ │ └── default
│ │ └── default.properties
│ │ └── python.properties
│ ├── specs
│ │ └── example.spec
│ └── step_impl
│ └── step_impl.py
│
└── Gauge-Sub-Project
├── env
│ └── default
│ └── default.properties
│ └── python.properties
├── specs
│ └── example.spec
└── step_impl
└── step_impl.py
Thanks!😄
Activity
Update getgauge/impl_loader.py
Correctly loading the methods from relatively imported classes (getga…
Update getgauge/impl_loader.py
Returning method_list in update_step_resgistry_with_class method (get…
Adding test class for relative import unittest (getgauge#365)
Adding unittest for relative import (getgauge#365)
Renaming method to update_step_registry_with_class (getgauge#365)
Updating unittest for impl loader (getgauge#365)
Bumping up python package version (getgauge#365)
Correctly loading the methods from relatively imported classes (#364)