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

ImportError: cannot import name 'given' from 'behave' #1095

Closed
mtrzas opened this issue Mar 29, 2023 · 4 comments
Closed

ImportError: cannot import name 'given' from 'behave' #1095

mtrzas opened this issue Mar 29, 2023 · 4 comments

Comments

@mtrzas
Copy link

mtrzas commented Mar 29, 2023

This error occurs when using behave 1.2.7.dev2

I got a python package(1) where actionwords for given, when and then are implemented inside a file /features/steps/actionwords.py

Inside another project(2) I want to import those actionwords inside a file /features/steps/example.py.

When running behave for project(2) I get the error message:

ImportError: cannot import name 'given' from 'behave' (/home/mike/projects/test/kanzidemo2/venv/lib/python3.10/site-packages/behave/__init__.py)

When I'm using behave 1.2.6 this error does not occur

@jenisys
Copy link
Member

jenisys commented Mar 29, 2023

Mmh, the complete test suite of behave imports the step-decorators from the behave module.
They are working, usable and actively checked by the tests.

Therefore, the fault location is probably somewhere in your workspace / work-environment.
Sorry, but without more details, it is rather hard to help you (to find out what is causing your problem).

@jenisys
Copy link
Member

jenisys commented Mar 29, 2023

PROCEDURE: To verify if problem exists or not

# -- USING: shell=bash
$ virtualenv -p python3.10 .venv
$ source .venv/bin/activate
$ python --version
Python 3.10.8

$ pip install git+https://github.com/behave/behave@v1.2.7.dev2
$ python explore_behave.py
behave import: OK

# -- USING: Main tip of the Git repository
$ pip install git+https://github.com/behave/behave
$ python explore_behave.py
behave import: OK

with Python script:

#!/usr/bin/env python3
# -- FILE: explore_behave.py
from __future__ import absolute_import, print_function

try:
    from behave import given, when, then
    print("behave import: OK")
except ImportError:
    print("behave-import: NOT-OK")
    raise

@realchandan
Copy link

It's importing but type hinting is not working

@jenisys
Copy link
Member

jenisys commented Jun 5, 2024

@realchandan

  • Which type hinting?

NOTES:

  • behave cannot provide type hints because it has still support for Python 2.7.
  • That does not mean that you cannot use type hints in your own source code (if you use Python3)
  • Any good editor or IDE will show you the parameters that you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants