diff --git a/README.md b/README.md index e3d7537..d0662cb 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ can better report on tests in their UI. ## About this fork -This is the fork repository based on https://github.com/chasleslr/dbt-junitxml/ version 0.1.5 -On top of that here were added: +This is the fork repository based on https://github.com/chasleslr/dbt-junitxml/ version 0.1.5 +On top of that here were added: 1. Support of DBT Core 1.3+ (originally it supported only up to 1.2). Versions 0.2.x Tested on DBT 1.5 2. In case of test failures Junit XML contains additional information regarding Stored Results and original test SQL. Details can be found below. 3. Test name in the resulted xml is more specific rather than in original version . @@ -20,24 +20,23 @@ Publishing as a regular pip module is considered pip install "git+https://github.com/SOVALINUX/dbt-junitxml@0.2.1#egg=dbt-junitxml" ``` -We recommend you to stick to some specific version, since newer versions might contain changes that may impact your operations (not being backward incompatible at all, but rather change some visualizations you might be used to). +We recommend you to stick to some specific version, since newer versions might contain changes that may impact your operations (not being backward incompatible at all, but rather change some visualizations you might be used to). ## Usage -When you run your dbt test suite, the output is saved under `target/run_results.json`. Run the following command -to parse your run results and output a jUnit XML formatted report named `report.xml`. +When you run your dbt test suite, the output is saved under `target/run_results.json` and `target/manifest.json`. Run the following command to parse your run results and output a jUnit XML formatted report named `report.xml`. ```shell -dbt-junitxml parse target/run_results.json report.xml +dbt-junitxml parse target/run_results.json target/manifest.json report.xml ``` ## Features description ### Rich XML output in case of test failure - -In order to help you handle test failures right where you see it we're adding supporting information into Junit XML in case of test failure -It's even more than you see in the DBT CLI console output! -For example: + +In order to help you handle test failures right where you see it we're adding supporting information into Junit XML in case of test failure +It's even more than you see in the DBT CLI console output! +For example: ``` Got 19 results, configured to fail if != 0 @@ -53,9 +52,9 @@ where reporter_employee_id is null ### Saving test SQL files for further analysis -Sometimes it's handy to see the exact SQL that was executed and tested by DBT without repeating compilation steps. -To achieve it we suggest you to save compiled tests SQL during your test run. -Below you can find a reference script: +Sometimes it's handy to see the exact SQL that was executed and tested by DBT without repeating compilation steps. +To achieve it we suggest you to save compiled tests SQL during your test run. +Below you can find a reference script: ```shell dbt test --store-failures mkdir -p target/compiled_all_sql && find target/compiled/ -name *.sql -print0 | xargs -0 cp -t target/compiled_all_sql/ @@ -64,7 +63,7 @@ zip -r -q compiled_all_sql.zip target/compiled_all_sql ### Integration with Report Portal -https://reportportal.io/ helps you to manage your test launches. Here at EPAM we're using this tool to manage over 4,000 DBT tests +https://reportportal.io/ helps you to manage your test launches. Here at EPAM we're using this tool to manage over 4,000 DBT tests In order to upload your test run to reportportal you can use the following script: ```shell @@ -81,4 +80,4 @@ Currently, only v4 of the [Run Results](https://docs.getdbt.com/reference/artifa ## Contribution -Development of this fork was partially sponsored by EPAM Systems Inc. https://www.epam.com/ +Development of this fork was partially sponsored by EPAM Systems Inc. https://www.epam.com/ diff --git a/src/dbt_junitxml/main.py b/src/dbt_junitxml/main.py index 804bd18..78f6e74 100644 --- a/src/dbt_junitxml/main.py +++ b/src/dbt_junitxml/main.py @@ -11,6 +11,10 @@ class InvalidRunResult(Exception): pass +def is_dbt_test(dict): + return dict["unique_id"].split(".")[0] == "test" + + def convert_timestamp_to_isoformat(timestamp: str) -> str: return datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ').strftime( '%Y-%m-%dT%H:%M:%S') @@ -48,14 +52,14 @@ def parse(run_result, manifest, output): if not schema_version == "https://schemas.getdbt.com/dbt/run-results/v4.json": raise InvalidRunResult("run_result.json other than v4 are not supported.") - if not executed_command == "test": + if not executed_command in ["test", "build"]: raise InvalidRunResult( - f"run_result.json must be from the output of `dbt test`. Got dbt {executed_command}.") + f"run_result.json must be from the output of `dbt test` or `dbt build`. Got dbt {executed_command}.") except KeyError as e: raise InvalidRunResult(e) - tests = run_result["results"] + tests = [d for d in run_result["results"] if is_dbt_test(d)] total_elapsed_time = run_result["elapsed_time"] test_suite_timestamp = convert_timestamp_to_isoformat(run_result["metadata"]["generated_at"])