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

source file names not properly printed with python 3.3.0 #80

Closed
javornikolov opened this issue Oct 28, 2012 · 4 comments
Closed

source file names not properly printed with python 3.3.0 #80

javornikolov opened this issue Oct 28, 2012 · 4 comments
Assignees
Labels
Milestone

Comments

@javornikolov
Copy link

With python 3.3.0 and behave 1.2.2 - "" is printed instead of the source file name when running behave. This is the output with the tutorial example:

$ behave example
Feature: showing off behave # example/example.feature:1

  Scenario: run a simple test        # example/example.feature:3
    Given we have behave installed   # <string>:3
    When we implement a test         # <string>:7
    Then behave will test it for us! # <string>:11


1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.0s

With python 2.7 3 it works as expected:

...
  Scenario: run a simple test        # example/example.feature:3
    Given we have behave installed   # example/steps/example.py:3
    When we implement a test         # example/steps/example.py:7
    Then behave will test it for us! # example/steps/example.py:11
...
@jenisys
Copy link
Member

jenisys commented Oct 31, 2012

I can confirm that I can reproduce your issue w/ python3.3 and --format=pretty.
In addition, several other issues seem to exist with this python version.

For example, an XML/Unicode problem occurs when using the --junit reporter:

$ behave --junit ...
...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.3/bin/behave", line 9, in <module>
    load_entry_point('behave==1.2.2', 'console_scripts', 'behave')()
...
  File ".../python3.3/site-packages/behave/reporter/junit.py", line 125, in feature
    tree.write(open(report_filename, 'w'), 'utf8')
  File ".../python3.3/xml/etree/ElementTree.py", line 828, in write
    serialize(write, self._root, qnames, namespaces)
  File ".../python3.3/contextlib.py", line 66, in __exit__
    self.gen.throw(type, value, traceback)
...
  File ".../python3.3/contextlib.py", line 200, in _exit_wrapper
    callback(*args, **kwds)
TypeError: must be str, not bytes

Therefore, I would advise you to use another Python version until all these issues are fixed.

@jenisys
Copy link
Member

jenisys commented Oct 31, 2012

I assume the problem is probably related to the step-loader mechanism that is currently used (exec() based mechanism). The wrong "filename" information is already missing when the steps are registered in the step-registry.

NOTE:
Python3.2 has the same problem. This occurs even when you use inspect.getfile(func) or inspect.getsourcefile(func) instead of the low-level attributes. In addition, the same junit problem exists in Python3.2

@jenisys
Copy link
Member

jenisys commented Oct 31, 2012

I located the problem. The behave.runner:exec_file() function uses a different implementation for Python3 compared to Python2. If you use the Python2 code part for Python3, you get the old behavior again. I only needed to use behave.model.relpath() (or os.path.relpath()) to reduce the absolute filename into a relative one.

NOTE:
The filename information for step definitions is only available if you call exec(code, ...) instead of calling it with exec(string, ...).

jenisys added a commit to jenisys/behave that referenced this issue Nov 2, 2012
jenisys added a commit to jenisys/behave that referenced this issue Nov 2, 2012
jenisys added a commit to jenisys/behave that referenced this issue Nov 2, 2012
jenisys added a commit to jenisys/behave that referenced this issue Nov 2, 2012
@jenisys
Copy link
Member

jenisys commented Nov 2, 2012

Provided fix and selftest for it (see above, but more Python3 issues are to be resolved).

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

No branches or pull requests

2 participants