I have a single folder for pytesting. In the folder I have conftest.py. The problem is conftest.py is starting to get to big. What is the simplest way I can have multiple conftest.py or imports to conftest.py while still being able to run python -m pytest or pytest --capture=no?

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'

other fixtures...

@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'
```

other fixtures...

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.

/r/learnpython Thread Parent