0

I am reporting data from some tests, and each test can have a 'summary' and a 'details' section. The 'summary' field for any particular test should be static, with any additional dynamic information going into the details field, as follows:

run_test()
if condition:
  report_test_data(summary="condition met", details=f"{component} ended with {state}")
else:
  report_test_data(summary="condition not met", details=f{component} ended with {state}")

However, this only applies to these calls to report_test_data, and there is nothing to stop another test from swapping these around, or putting all the data into the 'summary' field:

run_test()
if condition:
  report_test_data(summary=f"{component} ended with {state} - condition met", details="")
else:
  report_test_data(summary=f"{component} ended with {state} - condition not met", details="")

I am analyzing the test data based off the summary, so any particular ending state (e.g. condition = True) should have a static return string. I thought about making a class that manually defines every possible 'summary' string, but that quickly becomes untenable with more tests when a given test can have tens of possible ending states. The best option I can think of is if I could force the value passed into 'summary' to be a normal string. Is there any way to disallow passing f-strings into a particular function?

Note: I use pylint, so if there's an easy way to make it call these out, that would work as well.

tigerninjaman
  • 393
  • 3
  • 17
  • 1
    "I thought about making a class that manually defines every possible 'summary' string" If you end up going this route, using an [enum](https://docs.python.org/3/library/enum.html) could be a nice way to go about it. – Tzane Jan 11 '23 at 09:03
  • What do you mean by "static"? `summary="condition met, but only barely"` is a non-fstring, do you want to avoid passing that as well? – 9769953 Jan 11 '23 at 09:03
  • These tests will be run multiple times, so as long as the summary for a given test result is the same each time, I'm okay with it. What I am trying to avoid is the same result/state having different summaries. `TestA` ending in `StateA` should always have `summaryA`. – tigerninjaman Jan 11 '23 at 09:09

0 Answers0