<div dir="ltr"><div>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.</div><div><br></div><div>For instance:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">import r_group_analysis_dir.sar as sar</font></div></div><div><font face="monospace, monospace">import pytest</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">@pytest.fixture(scope='session', autouse=True)</font></div><div><font face="monospace, monospace">def start_qapp():</font></div><div><font face="monospace, monospace"> global _QAPP</font></div><div><font face="monospace, monospace"> from schrodinger.Qt import QtCore, QtWidgets</font></div><div><font face="monospace, monospace"> _QAPP = QtWidgets.QApplication.instance()</font></div><div><font face="monospace, monospace"> if not _QAPP:</font></div><div><font face="monospace, monospace"> _QAPP = QtWidgets.QApplication([])</font></div><div><font face="monospace, monospace"> return _QAPP</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">class TestSar(unittest.TestCase):</font></div><div><font face="monospace, monospace"> @classmethod</font></div><div><font face="monospace, monospace"> def setUpClass(cls):</font></div><div><font face="monospace, monospace"> cls.panel = sar.sarPanel()</font></div></blockquote><div><br></div><div>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 under xdist.</div><div><br></div><div>I guess I have two questions:</div><div>1. How should I ensure that start_qapp is run before any test or test setup?</div><div>2. Does this seem like a bug/RFE that I should report to pytest?</div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">- dan nealschneider<div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font color="#999999">(né wandschneider)</font></div><div><font color="#999999"><br></font></div><div><font color="#999999">Senior Developer</font></div><div><font color="#999999">Schr</font><span style="font-size:12.8px"><font color="#999999"><b>ö</b></font></span><span style="color:rgb(153,153,153);font-size:12.8px">dinger, Inc</span></div><div><font color="#999999">Portland, OR</font></div></blockquote><div><br></div></div></div></div></div></div></div></div>
</div>