Send test result reports by email.
Completed
Hello!
Can you help me?
I use TeamCity to run tests. Tests are run with pytest.
I want to send test reports by email.
How can I add information about the passed tests to the .ftl template?
Please sign in to leave a comment.
The implementation would require two steps; as a first step, you would register test suites you run via pytest with TeamCity, and as a second step, tests already acknowledged by TeamCity would be added to a template.
For the first step, I would suggest using service messages - these allow you to pass data into TeamCity by writing into stdout stream (echo or print() for Python) messages in predefined format. You may learn more about the supported messages here: https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingTests
As per my check, pytest would capture the stdout by default, so that TeamCity instance could never receive output from the test scripts. Either suppressing the capture (http://doc.pytest.org/en/latest/capture.html#accessing-captured-output-from-a-test-function), or calling the pytest from a higher-level script and printing out the service messages in the same script would be needed.
When you can see the test results on a Tests tab of Build Results page, you can use that data for the .ftl template. Overall details on the notification templates could be found at https://www.jetbrains.com/help/teamcity/customizing-notifications.html; as this paragraph (https://www.jetbrains.com/help/teamcity/customizing-notifications.html#CustomizingNotifications-DefaultDataModel) hints, you can use the classes of server-side API inside of the template. In order to retrieve the test instances, you could, for instance, use this chain:
http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/SBuild.html - interface for Build classes; use getBuildStatistics method to yield
http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/BuildStatistics.html - interface for BuildStatistics classes; use getAllTests to retrieve a collection of
http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/STestRun.html - interface for TestRun classes; represents a single test execution, along with its status.