Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Failed to reference from session/module scope #26

Closed
bcho opened this issue Mar 29, 2019 · 3 comments
Closed

Failed to reference from session/module scope #26

bcho opened this issue Mar 29, 2019 · 3 comments

Comments

@bcho
Copy link

bcho commented Mar 29, 2019

Hi, it seems that the plugin fixtures' default scope is function, when I try to reference the fixture from a fixture with session scope, py.test will raise a ScopeMismatch error.

My use case is:

  1. put a database schema init sql file to the data dir
  2. add a fixture call init_db, which has session scope, and it will recreate the database schema only once during the whole test execution
  3. init_db fixture use shared_datadir to read the init sql file

Any suggestions for this use case? Or can we change the plugin fixtures scope to session (or something else)?

@bcho
Copy link
Author

bcho commented Mar 29, 2019

After checking the code, it seems like the plugin requires reading dir from request.fspath, which is unavailable in session-scoped context... 😿

@nicoddemus
Copy link
Collaborator

Hi @bcho,

datadir is meant to be used for every test.

For your use case, doesn't seem like you need datadir at all. Can't you use the builtin tmp_path_factory instead?

@bcho
Copy link
Author

bcho commented Mar 29, 2019

@nicoddemus Understood! I solved my problem by extracting from current working dir from __file__. Thanks for your help 👍

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

No branches or pull requests

2 participants