I've been avoiding writing tests for some plugins....
# plugins
p
I've been avoiding writing tests for some plugins. The testing feels like a different level of abstraction and I question the value of tests in some cases. So, here's an example formatter plugin that runs some in-repo code as a Pex in a very simple rule. https://github.com/StackStorm/st2/compare/pants-plugins-schemas So, what would you test here? What value would the different kinds of tests listed in the testing docs provide for this plugin?
f
Some errors are not detected until runtime, for example rule graph errors.
Even a “trivial” test will still implicitly establish that no rule graph errors occurred.
Similar reasoning applies to trivial tests in general Python code: As useful as mypy is, it cannot cover everything and Python code should still have some “trivial” tests as compared to tests done for static languages to establish some assurance the code doesn’t throw an exception etc.
Just my view. Do as you will. :)
b
Take it from someone with several plugins and no tests. They all break eventually. Even a smoke test goes a long way
😆 2
I tend to upstream all mine for a few reasons. And as I do I am forced to write tests. Funny how I pretty much always find bugs when I do 😌
😂 1
w
I arguably overtest my internal plugins, even though some of them only I use. It's just a habit I've gotten into, and most of the tests are just sanities (does it run, is the result roughly correct) However, the tests can be useful to verify against regressions if you change your Pants version. I think that would be first and foremost. That's burned me a couple of times. Otherwise, if the plugin is simple enough and there is some level of constant runtime checking (e.g running the plugin in CI against your code or something), then the value of tests for small/simple tools is diminished. However, if you're pulling in optional config files, lots of options, fields, etc - then yeah. definitely more useful to test.
p
Oh. Pants upgrades. Yeah that's a really good point.
Thank you guys. Now I just need to figure out wiring up
./pants test
for plugins, even though I can't run it on the rest of the code base yet (tests hang under pytest... Converting from nosetest to pytest is a slow process).