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

Tables are not created for test_database while running behave test #136

Open
SALIMA534 opened this issue Mar 23, 2022 · 3 comments
Open

Comments

@SALIMA534
Copy link

We are using Behave tool for running BDD tests and when we run the tests using Behave only the tests are running fine. Here is an example to show how we are running test

behave login.feature

When we use the 'behave-django' to integrate BDD tests with Django, tests can't be run. We followed the steps available from these pages
https://behave-django.readthedocs.io/en/latest/installation.html
&
https://behave-django.readthedocs.io/en/latest/usage.html

and the error what we are hitting is like this:
Option 1:

python manage.py behave
.........
..........
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "C:\Users\USER 1\PycharmProjects\behaveproject\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "auth_user" does not exist
The above exception was the direct cause of the following exception:
.............
.............
django.db.utils.ProgrammingError: relation "auth_user" does not exist

Option 2:

python manage.py behave --keepdb
.........
.........
Using existing test database for alias 'default'...
Traceback (most recent call last):
  File "C:\Users\USER 1\PycharmProjects\behaveproject\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "auth_user" does not exist
The above exception was the direct cause of the following exception:
..........
..........
django.db.utils.ProgrammingError: relation "auth_user" does not exist

This is really blocking our deployments because tests can't be run. Could someone look at this issue and help us unblocking it.

@bittner
Copy link
Member

bittner commented Mar 24, 2022

It runs with just behave but not with python manage.py behave? Sounds like an issue with your Behave setup. Not with behave-django.

Do you have some special code in your environment.py, maybe, that makes the tests work? You have to share more details about your setup.

As an alternative, you could start with a simple setup from the tutorial, convince yourself that it's working, and add parts of your current setup to it until the test execution breaks.

@SALIMA534
Copy link
Author

Thank you @bittner. Yes, like I mentioned before running the tests just with behave works. As per document steps for behave-django we have to run python manage.py behave. Please check the instructions from this page

https://behave-django.readthedocs.io/en/latest/usage.html

Yes, To start browser we added code in environment.py ,

from selenium import webdriver

def before_all(context):
    # PhantomJS is used there (headless browser - meaning we can execute tests in a command-line environment, which is what we want for use with SemaphoreCI
    # For debugging purposes, you can use the Firefox driver instead.
    context.driver = webdriver.Chrome()

    # context.browser = webdriver.PhantomJS()
    context.browser.implicitly_wait(1)
    context.server_url = 'http://127.0.0.1:8000'


def after_all(context):
    # Explicitly quits the browser, otherwise it won't once tests are done
    context.browser.quit()


def before_feature(context, feature):
    # Code to be executed each time a feature is going to be tested
    pass

@bittner
Copy link
Member

bittner commented Mar 25, 2022

Is there a reason why you set context.server_url? What do you do with that value?

Can you try to use context.get_url() instead, as described in the instructions in the manual? Django's test client knows the server URL that the Django runserver uses.

Please, try to follow the manual closely, and only when that works fine, only then go about integrating Selenium (if you have to).

Aside, the description of your setup is still incomplete. You have to provide a minimal, reproducible example, otherwise it's very hard to help you.

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

No branches or pull requests

2 participants