Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to correctly loading the methods from relatively imported classes #365

Closed
kunalvishwasrao opened this issue Jul 3, 2024 · 0 comments
Assignees

Comments

@kunalvishwasrao
Copy link
Contributor

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:

  1. Initialize 2 gauge projects with gauge init python command
  2. Update the step_impl.py files for both the projects like shown above
  3. Setup the Gauge-Sub-Project/env/default/python.properties file like: STEP_IMPL_DIR = step_impl, ../Gauge-Main-Project/step_impl
  4. Create a spec file with the above mentioned steps
  5. Run the spec
  6. 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!😄

@zabil zabil self-assigned this Jul 3, 2024
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 3, 2024
Correctly loading the methods from relatively imported classes (getgauge#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

Co-authored-by: Zabil Cheriya Maliackal <zabil@users.noreply.github.com>
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 3, 2024
…uge#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 3, 2024
Correctly loading the methods from relatively imported classes (getgauge#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

Co-authored-by: Zabil Cheriya Maliackal <zabil@users.noreply.github.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 4, 2024
…gauge#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 4, 2024
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 4, 2024
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 4, 2024
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 4, 2024
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
kunalvishwasrao added a commit to kunalvishwasrao/gauge-python that referenced this issue Jul 5, 2024
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
zabil added a commit that referenced this issue Jul 6, 2024
* Bump the pip-dependencies group with 2 updates (#358)

Bumps the pip-dependencies group with 2 updates: [importlib-metadata](https://github.com/python/importlib_metadata) and [setuptools](https://github.com/pypa/setuptools).

Updates `importlib-metadata` from 7.1.0 to 7.2.1
- [Release notes](https://github.com/python/importlib_metadata/releases)
- [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst)
- [Commits](python/importlib_metadata@v7.1.0...v7.2.1)

Updates `setuptools` from 70.0.0 to 70.1.0
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v70.0.0...v70.1.0)

---
updated-dependencies:
- dependency-name: importlib-metadata
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: pip-dependencies
- dependency-name: setuptools
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: pip-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Bump the pip-dependencies group across 1 directory with 3 updates (#362)

Bumps the pip-dependencies group with 3 updates in the / directory: [debugpy](https://github.com/microsoft/debugpy), [importlib-metadata](https://github.com/python/importlib_metadata) and [setuptools](https://github.com/pypa/setuptools).

Updates `debugpy` from 1.8.1 to 1.8.2
- [Release notes](https://github.com/microsoft/debugpy/releases)
- [Commits](microsoft/debugpy@v1.8.1...v1.8.2)

Updates `importlib-metadata` from 7.2.1 to 8.0.0
- [Release notes](https://github.com/python/importlib_metadata/releases)
- [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst)
- [Commits](python/importlib_metadata@v7.2.1...v8.0.0)

Updates `setuptools` from 70.1.0 to 70.1.1
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v70.1.0...v70.1.1)

---
updated-dependencies:
- dependency-name: debugpy
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: pip-dependencies
- dependency-name: importlib-metadata
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: pip-dependencies
- dependency-name: setuptools
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: pip-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Support for relative imports to reuse step impls

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Update release dependencies

Signed-off-by: BugDiver <vinayshankar00@gmail.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Correctly loading the methods from relatively imported classs (addition to #360)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Update getgauge/impl_loader.py

Correctly loading the methods from relatively imported classes (#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

Co-authored-by: Zabil Cheriya Maliackal <zabil@users.noreply.github.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Returning method_list in update_step_resgistry_with_class method (#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Adding test class for relative import unittest (#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Adding unittest for relative import (#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Renaming method to update_step_registry_with_class (#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Updating unittest for impl loader (#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

* Bumping up python package version (#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
Signed-off-by: BugDiver <vinayshankar00@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Vinay Shukla <vinayshankar00@gmail.com>
Co-authored-by: Zabil Cheriya Maliackal <zabil@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants