|
19 | 19 |
|
20 | 20 |
|
21 | 21 | def pytest_addoption(parser):
|
22 |
| - # TODO: options for S3 bucket, credentials, ... |
23 | 22 | # TODO: option to always upload (also on success).
|
24 | 23 | parser.addoption(
|
25 |
| - "--upload-assets-runid", |
| 24 | + "--upload-assets-run-id", |
26 | 25 | metavar="ID",
|
27 | 26 | action="store",
|
28 | 27 | help="The run ID to use for building the S3 key.",
|
29 | 28 | )
|
| 29 | + parser.addoption( |
| 30 | + "--upload-assets-endpoint-url", |
| 31 | + metavar="URL", |
| 32 | + action="store", |
| 33 | + help="The S3 endpoint URL to upload to.", |
| 34 | + ) |
| 35 | + parser.addoption( |
| 36 | + "--upload-assets-bucket", |
| 37 | + metavar="BUCKET", |
| 38 | + action="store", |
| 39 | + help="The S3 bucket to upload to.", |
| 40 | + ) |
30 | 41 |
|
31 | 42 |
|
32 | 43 | def pytest_configure(config: pytest.Config):
|
| 44 | + run_id = config.getoption("upload_assets_run_id") |
| 45 | + endpoint_url = config.getoption("upload_assets_endpoint_url") |
| 46 | + bucket = config.getoption("upload_assets_bucket") |
33 | 47 | if (
|
34 |
| - # TODO only register if enough config is available for setup |
| 48 | + endpoint_url |
| 49 | + and bucket |
35 | 50 | # Don't register on xdist worker nodes
|
36 |
| - not hasattr(config, "workerinput") |
| 51 | + and not hasattr(config, "workerinput") |
37 | 52 | ):
|
38 | 53 | s3_client = boto3.client(
|
39 | 54 | service_name="s3",
|
40 | 55 | aws_access_key_id=os.environ.get("UPLOAD_ASSETS_ACCESS_KEY_ID"),
|
41 | 56 | aws_secret_access_key=os.environ.get("UPLOAD_ASSETS_SECRET_ACCESS_KEY"),
|
42 |
| - # TODO Option for endpoint url |
43 |
| - endpoint_url=os.environ.get("UPLOAD_ASSETS_ENDPOINT_URL"), |
| 57 | + endpoint_url=endpoint_url, |
44 | 58 | )
|
45 |
| - bucket = os.environ.get("UPLOAD_ASSETS_BUCKET") |
46 | 59 | config.pluginmanager.register(
|
47 |
| - S3UploadPlugin( |
48 |
| - run_id=config.getoption("upload_assets_runid"), |
49 |
| - s3_client=s3_client, |
50 |
| - bucket=bucket, |
51 |
| - ), |
| 60 | + S3UploadPlugin(run_id=run_id, s3_client=s3_client, bucket=bucket), |
52 | 61 | name=_PLUGIN_NAME,
|
53 | 62 | )
|
54 | 63 |
|
|
0 commit comments