Created
March 24, 2021 09:29
-
-
Save skhomuti/8939eea9c9157ebb10e10a594d9ce3ce to your computer and use it in GitHub Desktop.
clear attachments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from typing import List | |
import pytest | |
from _pytest.nodes import Item | |
from allure_commons.model2 import TestResult, Attachment | |
from allure_pytest.listener import AllureListener | |
def allure_listener(config) -> AllureListener: | |
listener: AllureListener = next( | |
filter( | |
lambda plugin: (isinstance(plugin, AllureListener)), | |
dict(config.pluginmanager.list_name_plugin()).values(), | |
), | |
None, | |
) | |
return listener | |
@pytest.hookimpl(hookwrapper=True) | |
def pytest_runtest_call(item: Item): | |
yield | |
listener = allure_listener(item.config) | |
reporter = listener.allure_logger | |
test_result: TestResult = reporter.get_test(None) | |
attachments: List[Attachment] = test_result.attachments | |
os.remove(os.path.join("path", "to", "report", attachments[0].source)) | |
test_result.attachments = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment