[TIP] pytest fixtures started after unittest.TestCase.setUpClass
dan.nealschneider at schrodinger.com
Thu Jan 4 13:27:53 PST 2018
We use session-scoped pytest fixtures to create the test environment that
we want, and to help reduce certain types of problems in tests. However,
I've noticed that pytest fixtures are run after
unittest.TestCase.setUpClass. This causes a problem when a setUpClass
relies on our global setup, and happens to be the first test executed.
import r_group_analysis_dir.sar as sar
from schrodinger.Qt import QtCore, QtWidgets
_QAPP = QtWidgets.QApplication.instance()
if not _QAPP:
_QAPP = QtWidgets.QApplication()
cls.panel = sar.sarPanel()
It seems to me that unittest's setUpClass should be behave as a
class-scoped fixture, and therefor be run after the session-scoped
start_qapp. I understand that this is not how the pytest's unittest
execution structure works, however. My workaround is triggering start_qapp
in the pytest_runtest_setup hook so that it will always be available, even
I guess I have two questions:
1. How should I ensure that start_qapp is run before any test or test setup?
2. Does this seem like a bug/RFE that I should report to pytest?
- dan nealschneider
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python