connect
connect copied to clipboard
investigate behave-django instead of django-behave
https://github.com/mixxorz/behave-django
I was contacted by the maintainer, who said:
In terms of usage, behave-django has you invoke a custom management command,
python manage.py behave
, to run your BDD tests, instead of replacing the TEST_RUNNER. This has the advantage of separating BDD tests from regular unit tests. Aside from that difference in approach, behave-django has more features that can help people with their tests.
Database transactions per scenario
Use Django's testing client
Use unittest + Django assert library
Use behave's command line arguments
Use behave's configuration file
Fixture loading
You can skim through the docs to see how all of this works. https://pythonhosted.org/behave-django/
In my unbiased opinion ( :P), I think behave-django does a better job at integrating BDD tests with django. It's easier to use and a lot more flexible.
Given that we haven't been 100% happy with django-behave, it may be worth a look? Since it also uses behave, it should require too many (any?) changes to our actual test code?
┆Issue is synchronized with this Asana task
Yes please so that we could move them back to connect.bdd
Sounds like it's at least worth trying. There is only one way to find out...
Don't get your hopes up Remy, I think behave-django requires you to put your features in a folder named "features" :-P
@hjwp I started porting this and had some trouble setting up my environment.py. The first scenario runs fine, but then I get this error:
Exception OSError: [Errno 98] Address already in use
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave_django/management/commands/behave.py", line 59, in handle
return_code = behave_main(args=sys.argv[2:])
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave/__main__.py", line 109, in main
failed = runner.run()
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave/runner.py", line 672, in run
return self.run_with_paths()
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave/runner.py", line 693, in run_with_paths
return self.run_model()
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave/runner.py", line 483, in run_model
failed = feature.run(self)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave/model.py", line 523, in run
failed = scenario.run(runner)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave/model.py", line 1255, in run
failed = scenario.run(runner)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave/model.py", line 867, in run
runner.run_hook('before_scenario', runner.context, self)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave/runner.py", line 405, in run_hook
self.hooks[name](context, *args)
File "features/environment.py", line 61, in before_scenario
environment.before_scenario(context, scenario)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/behave_django/environment.py", line 17, in before_scenario
context.test.setUpClass()
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/django/test/testcases.py", line 1261, in setUpClass
raise cls.server_thread.error
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/django/test/testcases.py", line 1163, in run
(self.host, port), QuietWSGIRequestHandler)
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/django/core/servers/basehttp.py", line 76, in __init__
super(WSGIServer, self).__init__(*args, **kwargs)
File "/usr/lib64/python3.3/socketserver.py", line 430, in __init__
self.server_bind()
File "/home/nicky/.virtualenvs/django_connect/lib/python3.3/site-packages/django/core/servers/basehttp.py", line 80, in server_bind
super(WSGIServer, self).server_bind()
File "/usr/lib64/python3.3/wsgiref/simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "/usr/lib64/python3.3/http/server.py", line 135, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/lib64/python3.3/socketserver.py", line 441, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use
My updated environment.py:
...
from behave_django import environment
def before_scenario(context, scenario):
# Reset the database before each scenario - probably don't need this anymore
management.call_command('flush', verbosity=0, interactive=False)
context.browser = Browser('phantomjs')
context.server_url = 'http://localhost:8081/' # can remove this and replace in tests with built in context.base_url
# Then recreate our base data
site = Site.objects.get(domain='example.com')
try:
site_config = SiteConfig.objects.get(site=site)
except ObjectDoesNotExist:
site_config = SiteConfigFactory(site=site)
# Setup skills
SkillFactory(name='skill1')
SkillFactory(name='skill2')
# Setup roles
RoleFactory(name='role1')
RoleFactory(name='role2')
RoleFactory(name='role3')
environment.before_scenario(context, scenario) # This is the line where I am seeing the failure :(
Thoughts?
Might be relevant: http://stackoverflow.com/questions/20619846/djangos-liveservertestcase-always-fails-due-to-conflicting-address-despite-a