@@ -19,7 +19,7 @@ def pytest_addoption(parser):
1919 parser .addoption ("--globals" , default = "" )
2020
2121
22- def self_signed_cert (test_dir , name ):
22+ def self_signed_cert (name ):
2323 k = crypto .PKey ()
2424 k .generate_key (crypto .TYPE_RSA , 2048 )
2525 cert = crypto .X509 ()
@@ -29,11 +29,9 @@ def self_signed_cert(test_dir, name):
2929 cert .gmtime_adj_notAfter (365 * 86400 ) # 365 days
3030 cert .set_pubkey (k )
3131 cert .sign (k , "sha512" )
32- (test_dir / f"{ name } .key" ).write_text (
33- crypto .dump_privatekey (crypto .FILETYPE_PEM , k ).decode ("utf-8" )
34- )
35- (test_dir / f"{ name } .crt" ).write_text (
36- crypto .dump_certificate (crypto .FILETYPE_PEM , cert ).decode ("utf-8" )
32+ return (
33+ crypto .dump_privatekey (crypto .FILETYPE_PEM , k ),
34+ crypto .dump_certificate (crypto .FILETYPE_PEM , cert ),
3735 )
3836
3937
@@ -66,7 +64,7 @@ def nginx_config(request, pytestconfig, testdir, logger):
6664
6765
6866@pytest .fixture (scope = "module" )
69- def nginx (testdir , pytestconfig , nginx_config , certs , logger , otelcol ):
67+ def nginx (testdir , pytestconfig , nginx_config , cert , logger , otelcol ):
7068 (testdir / "nginx.conf" ).write_text (nginx_config )
7169 logger .info ("Starting nginx..." )
7270 proc = subprocess .Popen (
@@ -96,5 +94,8 @@ def nginx(testdir, pytestconfig, nginx_config, certs, logger, otelcol):
9694
9795
9896@pytest .fixture (scope = "module" )
99- def certs (testdir ):
100- self_signed_cert (testdir , "localhost" )
97+ def cert (testdir ):
98+ key , cert = self_signed_cert ("localhost" )
99+ (testdir / "localhost.key" ).write_text (key .decode ("utf-8" ))
100+ (testdir / "localhost.crt" ).write_text (cert .decode ("utf-8" ))
101+ yield (key , cert )
0 commit comments