-
Notifications
You must be signed in to change notification settings - Fork 322
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
Silently fails when "Backgound" has step with accent "ñ" #478
Comments
Can you show the corresponding step file? |
@michelts here you have. The step is at the bottom. If I change # terrain.py
# -*- coding: utf-8 -*-
# ...
@steps
class CoreSteps(object):
"""
Methods in exclude or starting with _
will not be considered as step
"""
exclude = []
def __init__(self, env, tc):
self.env = env
self.tc = tc
def existe_un_usuario(self, step, username, password):
'''.* existe un usuario "([^"]*)" con contraseña "([^"]*)"'''
from django.contrib.auth.models import User
User.objects.create_user(username=username, password=password)
# ...
CoreSteps(world, TestCase('__init__')) |
I use functions instead classes to define steps, but I suspect the problem is at the step regular expression. Can you try using an unicode string? For instance: def existe_un_usuario(self, step, username, password):
u'''.* existe un usuario "([^"]*)" con contraseña "([^"]*)"'''
from django.contrib.auth.models import User
User.objects.create_user(username=username, password=password) Another way to figure out these type of problems it to write te context in the scenario at first and, when the context if passing, I move it from scenario to context again. This is not the fix for the bug related here, but can help you use lettuce until it is fixed! |
Thanks! using |
I don't agree. It is a bug since lettuce fails silently. It should tell the step was not found for contexts too. Try the same approach in a scenario instead of a context... |
True. I misunderstood your previous comment. |
When a step fails in "Background" (for example because of a NoDefinitionFound exception), the exception is caught by Runner.run(...) and printed out directly which raises a UnicodeEncodeError exception. This exception is hidden by the finally statement which returns an empty list (as if there wasn't any scenario in the file)... If you run lettuce using the --failfast flag, you'll notice the error but the failure won't be taken into account when we set the exit code. |
As explained in gabrielfalcao#478, when a step in the Background contains an non-ASCII character, the user is not warned. I don't find any other convincing fix for this problem...
Ok... so it's not as easy as I excepted. Python 2 is not designed to handle non-ASCII characters in exception messages (see [1]). There are several possibilities to fix that but I don't like any of them:
Whatever our choice, our english-speaking friends won't appreciate seeing their code rotten with hacks to cope with foreign languages... This bug is not as catastrophical as it looks like because the exit code is defined correctly (even if nothing is printed out in verbose mode...). Last idea: we could mention the error in the summary at the end of the output. [1] https://pythonhosted.org/kitchen/unicode-frustrations.html (Frustration #5: Exceptions). |
Note the
ñ
inContexto
, changing that it just works. If I putpassword
instead ofcontraseña
it works.It just silently fails:
The text was updated successfully, but these errors were encountered: