<div dir="ltr">Hum<div>TestMixin was to provide a simple helper. A good case to be converted to a fixture(s)</div><div><br></div><div>The code above was created for a good reason but for the life of me I cannot remember as it was a few years ago.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 9 Oct 2019 at 20:10, Benjamin Hoving <<a href="mailto:benjamin.hoving@gmail.com">benjamin.hoving@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_2083807120151392760__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">
Just a quick follow up for finding other places where the QApplication object is created.<br><br><div></div>
<div>I just one other place in the testing code (other than the TestMixin class): </div><div><a href="https://gitlab.com/openlp/openlp/blob/master/tests/functional/__init__.py#L28" target="_blank">https://gitlab.com/openlp/openlp/blob/master/tests/functional/__init__.py#L28</a></div><div>This line is run any time the module path is imported which would explain why the QApplication object code in the TestMixin class never creates a new object, but always reuses an existing object.</div><div><br></div><div>- Ben</div><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px;min-width:500px">
<p style="color:rgb(170,170,170);margin-top:10px">On 10/8/2019 9:55:24 PM, Benjamin Hoving <<a href="mailto:benjamin.hoving@gmail.com" target="_blank">benjamin.hoving@gmail.com</a>> wrote:</p><div style="font-family:Arial,Helvetica,sans-serif"><div id="gmail-m_2083807120151392760__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">That sounds similar. One odd thing in this scenario is that the currently enabled tests don't cause the segfault, which means that something about those tests is different from the ones that are currently disabled (TestOpenLP). The only difference I can find is that the TestOpenLP class actually requires an instance of OpenLP rather than a generic QApplication instance like what is created in the TestMixin class.<div><br><div></div>
<div>The current TestMixin class has a setup_application method that attempts to get the current QApplication instance and either reuses that instance if it exists or creates a new one.</div><div><br></div><div>Another odd thing is that if I put a print statement <span style="font-size:13.3333px">that prints whether the QApplication was reused or created</span><span style="font-size:10pt"> in the TestMixin.setup_application method, it never runs the 'created' branch - it always runs the 'reused' branch which means that the QApplication object is being initially created somewhere other than the TestMixin.setup_application method and then all calls to the setup_application method use the 'reuse' branch because the QApplication object already exists. I haven't figured that one out yet. I'm going to look into it more later tonight and see if I can find where the object is being created.</span></div></div><div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">All these tests are running on the current unittest tests from the master branch with the pytest runner. The only thing I change is to make the TestOpenLP class inherit from TestMixin </span><span style="font-size:13.3333px">(the tests crash with AttributeError's if the class is not inherited.)</span><span style="font-size:10pt"> and there is a call to patch that has an outdated module path. I can publish the testing branch if that would be helpful. Not sure if a merge request is appropriate if I don't actually have a solution. </span></div><div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">I think I had a branch at one point that had the TestOpenLP tests running and passing with the unittest test runner but not the pytest runner, but I'm not sure if I kept that branch around.</span></div><div><br></div><div>- Ben</div><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px;min-width:500px">
<p style="color:rgb(170,170,170);margin-top:10px">On 10/8/2019 6:51:48 PM, John Morris <<a href="mailto:johnathan.morris.58@gmail.com" target="_blank">johnathan.morris.58@gmail.com</a>> wrote:</p><div style="font-family:Arial,Helvetica,sans-serif"><div dir="auto">I ran into an issue like what you are describing....I created a workaround using an underlying part of pytest that runs before the startup function to creat a global variable. Then when startup ran it changed the state of the variable and did not recreate the offending object....I know this is a hack....but it might spark an idea.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 8, 2019, 6:32 PM Benjamin Hoving <<a href="mailto:benjamin.hoving@gmail.com" target="_blank">benjamin.hoving@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;min-width:500px"><div id="gmail-m_2083807120151392760m_-4934852301326588340__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">
I haven't had a chance to try anything, but I think the fix for that would be to call Registry().create() before each test, which could be done easily (and even automatically, I think) from a fixture.<div></div>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px;min-width:500px">
<p style="color:rgb(170,170,170);margin-top:10px">On 10/8/2019 6:29:07 PM, Raoul Snyman via openlp-dev <<a href="mailto:openlp-dev@openlp.io" rel="noreferrer" target="_blank">openlp-dev@openlp.io</a>> wrote:</p><div style="font-family:Arial,Helvetica,sans-serif">On 2019-10-08 15:22, Benjamin Hoving wrote:<br>> The basic problem is that the QApplication object is only meant to be<br>> instantiated once for the lifetime of the application, which is what<br>> happens during the normal execution of OpenLP, but during testing, the<br>> QApplication is created and destroyed many times and references to the<br>> object may not always be torn down between tests. I personally suspect<br>> (though I have not had a chance to fully investigate) that the<br>> Settings object or some of the singleton objects may be keeping<br>> references to the QApplication object. (for instance, I know that the<br>> Registry singleton is explicitly given a reference to the QApplication<br>> object and I don't think the Registry object is destroyed between<br>> tests). This makes it very difficult to pinpoint the actual point of<br>> failure for a test because the point of failure may be caused as a<br>> side effect of another test failing to tear the environment down<br>> properly. (i.e. one that initialized the Registry and gave it a<br>> QApplication reference, but did not reset the Registry).<br><br>Aha. You might be onto something here. I'm not sure how well we reset <br>the Registry object, if at all, during tests.<br><br>-- <br>Raoul Snyman<br><a href="mailto:raoul@snyman.info" rel="noreferrer" target="_blank">raoul@snyman.info</a><br>_______________________________________________<br>openlp-dev mailing list<br><a href="mailto:openlp-dev@openlp.io" rel="noreferrer" target="_blank">openlp-dev@openlp.io</a><br><a href="https://lists.openlp.io/mailman/listinfo/openlp-dev" rel="noreferrer" target="_blank">https://lists.openlp.io/mailman/listinfo/openlp-dev</a><br></div></blockquote></div>_______________________________________________<br>
openlp-dev mailing list<br>
<a href="mailto:openlp-dev@openlp.io" rel="noreferrer" target="_blank">openlp-dev@openlp.io</a><br>
<a href="https://lists.openlp.io/mailman/listinfo/openlp-dev" rel="noreferrer noreferrer" target="_blank">https://lists.openlp.io/mailman/listinfo/openlp-dev</a><br>
</blockquote></div>
_______________________________________________
openlp-dev mailing list
<a href="mailto:openlp-dev@openlp.io" target="_blank">openlp-dev@openlp.io</a>
<a href="https://lists.openlp.io/mailman/listinfo/openlp-dev" target="_blank">https://lists.openlp.io/mailman/listinfo/openlp-dev</a>
</div></blockquote></div></div></blockquote></div>_______________________________________________<br>
openlp-dev mailing list<br>
<a href="mailto:openlp-dev@openlp.io" target="_blank">openlp-dev@openlp.io</a><br>
<a href="https://lists.openlp.io/mailman/listinfo/openlp-dev" rel="noreferrer" target="_blank">https://lists.openlp.io/mailman/listinfo/openlp-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Tim and Alison Bentley<br>Home@TRARBentley.net<div style="display:inline"></div></div>