Skip to content

Commit 45e2a83

Browse files
authored
unregister pytest plugin (fixes #202 via #203)
1 parent 884581f commit 45e2a83

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

allure-pytest/src/plugin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,30 @@ def link_pattern(string):
8888
str.format().""")
8989

9090

91+
def cleanup_factory(plugin):
92+
def clean_up():
93+
name = allure_commons.plugin_manager.get_name(plugin)
94+
allure_commons.plugin_manager.unregister(name=name)
95+
return clean_up
96+
97+
9198
def pytest_configure(config):
9299
report_dir = config.option.allure_report_dir
100+
93101
test_helper = AllureTestHelper(config)
102+
# TODO: Why helper is present anyway?
94103
allure_commons.plugin_manager.register(test_helper)
104+
config.add_cleanup(cleanup_factory(test_helper))
95105

96106
if report_dir:
97107
test_listener = AllureListener(config)
98108
config.pluginmanager.register(test_listener)
99109
allure_commons.plugin_manager.register(test_listener)
110+
config.add_cleanup(cleanup_factory(test_listener))
100111

101112
file_logger = AllureFileLogger(report_dir)
102113
allure_commons.plugin_manager.register(file_logger)
114+
config.add_cleanup(cleanup_factory(file_logger))
103115

104116

105117
def pytest_collection_modifyitems(items, config):
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
import pytest
3+
4+
5+
def test_register_unregister(tmpdir):
6+
"""
7+
>>> allure_report = getfixture('allure_report')
8+
>>> assert_that(allure_report,
9+
... has_test_case('test_register_unregister',
10+
... with_status('passed')
11+
... )
12+
... )
13+
"""
14+
current_dir = os.path.dirname(os.path.realpath(__file__))
15+
target = os.path.join(current_dir, 'sample.py')
16+
allure_option = '--alluredir={dir}'.format(dir=tmpdir.mkdir('trash').strpath)
17+
assert pytest.main([allure_option, target]) == 0
18+
assert pytest.main([allure_option, target]) == 0
19+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import allure
2+
3+
4+
def test_sample():
5+
allure.attach('Peace!!!')

0 commit comments

Comments
 (0)