def pytest_sessionfinish(self):
        """
        We are done and have all the results in `self.suites`
        Lets write em down.

        But first we kinda-unify the test cases.

        We expect cases to come from AllureTestListener -- and the have ._id field to manifest their identity.

        Of all the test cases in suite.testcases we leave LAST with the same ID -- becase logreport can be sent MORE THAN ONE TIME
        (namely, if the test fails and then gets broken -- to cope with the xdist's -x behavior we have to have tests even at CALL failures)

        TODO: do it in a better, more efficient way
        """

        for s in self.suites.values():
            if s.tests:  # nobody likes empty suites
                s.stop = max(case.stop for case in s.tests)

                known_ids = set()
                refined_tests = []
                for t in s.tests[::-1]:
                    if t.id not in known_ids:
                        known_ids.add(t.id)
                        refined_tests.append(t)
                s.tests[::-1] = refined_tests

                with self.impl._reportfile('%s-testsuite.xml' % uuid.uuid4()) as f:
                    self.impl._write_xml(f, s)

        self.impl.store_environment()
dataset/ETHPy150Open allure-framework/allure-python/allure/pytest_plugin.py/AllureAgregatingListener.pytest_sessionfinish/original