Example 1
I think I should go into more detail of the original question.
def test_username_db():
is not the most useful fixture. But imagine I have many fixtures like that.
conftest.py.
Also I wrote the database class here.
``` @pytest.fixture def test_username_db(): # assume bob exists user_db = User.query.filter_by(username='Bob').first() assert user_db != 'Bob'
@pytest.fixture() def create_db(new_user):
bind_key="testing_app_db"
# Create the database and the database table
db.create_all(bind_key)
db.session.add(new_user)
db.session.commit()
# yield unlike return doesn't stop when called.
yield test_username_db()
yield other fixtures
db.drop_all(bind_key)
```
Example 2
Now imagine I want to split up the extra fixtures into functions in a file called test_function.py.
Also I wrote the database class here.
```
def test_username_db():
# assume bob exists
user_db = User.query.filter_by(username='Bob').first()
assert user_db != 'Bob'
```
conftest.py.
from tests.test_function import
@pytest.fixture() def create_db(new_user):
bind_key="testing_app_db"
# Create the database and the database table
db.create_all(bind_key)
db.session.add(new_user)
db.session.commit()
# yield unlike return doesn't stop when called.
yield test_username_db()
yield # other functions
db.drop_all(bind_key)
```
This seems okay but the problem is when I run the code in example 2 I get the error
Also my folder looks like this. https://imgur.com/a/CYd97uJ
Why is this error occurring? Also I using email_token_and_registration_confirmation_email
instead of test_username_db
. But the error and question still stands.