RedHatQE / pylero

Python wrapper for the Polarion WSDL API
https://redhatqe.github.io/pylero/
MIT License
37 stars 25 forks source link

[bug]: Conditionally import TestCase in TestRun can lead to errors #175

Closed AlthausKonstantin closed 8 months ago

AlthausKonstantin commented 8 months ago

Dear all,

I am sorry, but I have to reopen the problems already discussed at length in https://github.com/RedHatQE/pylero/pull/132, https://github.com/RedHatQE/pylero/issues/134, https://github.com/RedHatQE/pylero/pull/169.

Problem

Currently, in test_run.py we conditionally import the work item TestCase. If this work item does not exist, we just ignore that:

try:
    from pylero.work_item import TestCase
except ImportError:
    pass

cf. https://github.com/RedHatQE/pylero/blob/5f71bad7b2031035d5b0ed4c61a34c5151c15a57/src/pylero/test_run.py#L35C1-L39C1

This leads to problems because TestCase is still used in the subsequent code. E.g.:

            if test_record.result == "failed" and not test_record.defect_case_id:
                test_record.defect_case_id = create_incident_report(
                    self, test_record, TestCase(work_item_id=test_case_id)
                )

cf. https://github.com/RedHatQE/pylero/blob/5f71bad7b2031035d5b0ed4c61a34c5151c15a57/src/pylero/test_run.py#L1321C1-L1324C18

Question

I could not comprehend why the TestCase work item must be used instead of the generic _WorkItem class (cf. https://github.com/RedHatQE/pylero/pull/169). Can someone elaborate on that?

Proposal

If the TestCase class really must be used, I propose to conditionally create a TestCase class in test_run.py if this work item type does not exist. Something like this (in the following there are still missing the things that make the TestCase class indispensable):

try:
    from pylero.work_item import TestCase
except ImportError:
    class TestCase(_WorkItem):
        def __init__(self, *args, **kwargs):
            super(TestCase, self).__init__(*args, **kwargs)

What do you think about this?

leelavg commented 8 months ago
  1. I didn't try the proposal earlier and so I'm not sure if that works or not
  2. I did #169 in the assumption that import of TestCase will succeed if that exists in the server. If only _WorkItem is imported it'll fail when we use TestCase methods explicitly

You can look at end of work_item.py and see how work item types are generated with meta classes.

AlthausKonstantin commented 8 months ago

Okay, I will write a full-fledged TestRun to replace the MWE above.

I did https://github.com/RedHatQE/pylero/pull/169 in the assumption that import of TestCase will succeed if that exists in the server. If only _WorkItem is imported it'll fail when we use TestCase methods explicitly

Okay, thanks for clarifying. My goal is to make all the code in test_run.py work, even if the TestCase work item does not exist on the server.

leelavg commented 8 months ago

even if the TestCase work item does not exist on the server.

  • that was more than a bit involved for me 😅, by all means pls go ahead if you want to give it a try and thanks a lot for all your contributions!