-
-
Notifications
You must be signed in to change notification settings - Fork 69
Configuring Qt API in pytest.ini #129
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
Comments
Just dropping by to say hi. Although it's not a big problem to have to set |
I think this is the way to go.
I agree that it would be painful and easy to miss some imports due to this, but we could instead implement lazy importing like from qt_compat import qt_api
@pytest.yield_fixture(scope='session')
def qapp():
"""
fixture that instantiates the QApplication instance that will be used by
the tests.
"""
app = qt_api.QApplication.instance()
if app is None:
global _qapp_instance
_qapp_instance = qt_api.QApplication([])
yield _qapp_instance
else:
yield app # pragma: no cover
def pytest_configure(config):
qt_api.set_qt_api(config.getoption('qt_api')) # at this point import the correct module and inject the classes as attributes of qt_api instance |
Wrote a quick proof of concept in #130 |
In
#pylib
I discussed with @estan if there's some good way to configurePYTEST_QT_API
in a way which doesn't require passing it on the commandline, for cases where you always need it to be e.g.pyqt5
.Unfortunately using pytest-env doesn't work as it uses
pytest_load_initial_conftestst
which will be run afterpytest-qt
is already imported.One possibility would be to change
pytest-qt
so it reads the API version frompytest.ini
. This should be doable but is probably quite painful, as it reqires delaying any imports fromqt_compat
until afterpytest_load_initial_conftests
(i.e. moving a lot of imports inside functions...).Another possibility would be to add an
env
option to pytest's core, but pytest would need to read it (and set the environment variables) before any plugins are loaded...Alternatively
pytest-qt
could search apytestqt.ini
or so in the current directory, but that'd also break in various circumstances and isn't really nice either.What do you think?
The text was updated successfully, but these errors were encountered: