source: mod_gnutls/test/tests/24_pkcs11_cert/hooks.py

main
Last change on this file was 5357109, checked in by Fiona Klute <fiona.klute@…>, 2 years ago

Fix flake8 warnings in test hooks.py

  • Property mode set to 100644
File size: 637 bytes
Line 
1#!/usr/bin/python3
2import os
3import mgstest.softhsm
4from pathlib import Path
5from unittest import SkipTest
6
7
8def prepare_env():
9    if not mgstest.softhsm.find_softhsm_bin():
10        raise SkipTest('SoftHSM not found.')
11
12    db = 'authority/server/softhsm2.db'
13    softhsm_conf = mgstest.softhsm.tmp_softhsm_conf(db)
14
15    def cleanup():
16        print(f'Delete {softhsm_conf}')
17        Path(softhsm_conf).unlink()
18
19    try:
20        token = mgstest.softhsm.Token(config_file=softhsm_conf)
21        for key, value in token.test_env.items():
22            os.environ[key] = value
23    except:
24        cleanup()
25        raise
26
27    return cleanup
Note: See TracBrowser for help on using the repository browser.