Skip to content

Does fixtures work across applications? #508

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

Closed
tony opened this issue Aug 24, 2017 · 3 comments
Closed

Does fixtures work across applications? #508

tony opened this issue Aug 24, 2017 · 3 comments

Comments

@tony
Copy link
Member

tony commented Aug 24, 2017

Assume this structure:

./project/app/tests/__init__.py
./project/app/tests/conftest.py

./project/app2/tests/__init__.py
./project/app2/tests/test_this.py

is pytest-django designed to have conftest's fixtures available project wide, so this_this.py in app2 would have access to it?

(I'm trying to determine if this is an issue on my end, a bug or a feature request)

@tony
Copy link
Member Author

tony commented Aug 24, 2017

py.test --create-db
============================= test session starts ==============================
platform darwin -- Python 3.6.2, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
Django settings: develtech.settings.local (from ini file)
rootdir: /Users/me/work/develtech, inifile: setup.cfg
plugins: factoryboy-1.3.1, django-3.1.2
collected 25 items

develtech/based_threads/tests/test_thread.py EE
develtech/core/tests/test_context_processors.py .
develtech/core/tests/test_growth.py ............
develtech/core/tests/test_utils.py ..........

==================================== ERRORS ====================================
________________________ ERROR at setup of test_thread _________________________
file /Users/me/work/develtech/develtech/based_threads/tests/test_thread.py, line 9
  def test_thread(db, admin_user, user):
E       fixture 'user' not found
>       available fixtures: _dj_autoclear_mailbox, _django_clear_site_cache, _django_db_marker, _django_set_urlconf, _django_setup_unittest, _fail_for_invalid_template_variable, _live_server_helper, _template_string_if_invalid_marker, admin_client, admin_user, cache, capfd, capsys, client, db, django_db_blocker, django_db_keepdb, django_db_modify_db_settings, django_db_modify_db_settings_xdist_suffix, django_db_setup, django_db_use_migrations, django_test_environment, django_user_model, django_username_field, doctest_namespace, factoryboy_request, live_server, mailoutbox, monkeypatch, pytestconfig, record_xml_property, recwarn, rf, settings, tmpdir, tmpdir_factory, transactional_db
>       use 'pytest --fixtures [testpath]' for help on them.

/Users/me/work/develtech/develtech/based_threads/tests/test_thread.py:9
______________________ ERROR at setup of test_score_count ______________________
file /Users/me/work/develtech/develtech/based_threads/tests/test_thread.py, line 64
  def test_score_count(db, admin_user, user):
E       fixture 'user' not found
>       available fixtures: _dj_autoclear_mailbox, _django_clear_site_cache, _django_db_marker, _django_set_urlconf, _django_setup_unittest, _fail_for_invalid_template_variable, _live_server_helper, _template_string_if_invalid_marker, admin_client, admin_user, cache, capfd, capsys, client, db, django_db_blocker, django_db_keepdb, django_db_modify_db_settings, django_db_modify_db_settings_xdist_suffix, django_db_setup, django_db_use_migrations, django_test_environment, django_user_model, django_username_field, doctest_namespace, factoryboy_request, live_server, mailoutbox, monkeypatch, pytestconfig, record_xml_property, recwarn, rf, settings, tmpdir, tmpdir_factory, transactional_db
>       use 'pytest --fixtures [testpath]' for help on them.

/Users/me/work/develtech/develtech/based_threads/tests/test_thread.py:64
====================== 23 passed, 2 error in 4.08 seconds ======================
make[1]: *** [test] Error 1

I do notice that my application without the conftest.py runs before the application that holds the conftest.py.

My intuition was perhaps conftest.py fixtures would be aggregated or there would be a place to store them.

A second thing I noticed: the user fixture I have is generated from factory.django.DjangoModelFactory:

class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = get_user_model()

    username = factory.Sequence(lambda n: "user%03d" % n)
    password = factory.Sequence(lambda n: "pass%03d" % n)


register(UserFactory)

I'm going to make an issue over there to rule out if this behavior is on pytest-django, factory_boy, or my end.

@bluetech
Copy link
Member

is pytest-django designed to have conftest's fixtures available project wide, so this_this.py in app2 would have access to it?

No, fixtures defines in a conftest only apply to the directory tree in which the conftest is located.

Sorry, I do not understand the rest of the comment.

@tony
Copy link
Member Author

tony commented Oct 16, 2020

@bluetech Thank you very much. I am not familiar with the context I originally had for this message - if I remember I will bring it up

For now I will consider this issue addressed

@tony tony closed this as completed Oct 16, 2020
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