[question] Run only unit tests while developing
My question is related to #11898, but mine focuses on developer usage rather than CI. As a developer, I would like to run only the unit tests during my code/test/debug/refactor development cycle. But when I'm ready to create a package for testing with other packages, I would like to run all of the tests.
One way to accomplish this would be to add a develop boolean option to my recipe that appropriately filters the tests to run, and do conan install with -o develop=True to set up my development environment. When I want to create a package for testing, I would run conan create, and it would run all the tests because the develop option would be False in that case. Any suggestions on how to make such a usage model work without me having to remember to add -o develop=True when I run conan install? In other words, how can I have develop default to True for conan install and False for conan create?
- [X] I've read the CONTRIBUTING guide.
Hi @blackk-foxx
A couple of quick hints:
- You don't want to use an option, if the final package binaries are not different (which typically shouldn't be for tests, unless for some unusual reason you are also packaging the tests themselves), because then you would need to remove the option in
package_id - You can probably better use a
conf, that you can set both in your command line-cand profiles. - With a
conf, same as options you can define the semantics you want, but it is true that the semantics for the conf will remain the same between aconan installand aconan create, and this is on purpose, as the rationale for this was that by default conan should do exactly the same for create and for install, to have better reproducibility. You still need one of them to be specified. Asconan createtypically happens more in CI than in developer machines, I'd recommend to let theconan createbe the one that specifies the conf value, and not theconan installthat developers use more often
Finally, Conan 2.0 will provide a framework for creating custom commands, you will be able to define your own create command if you want it, changing the semantics, or actually injecting the conf that you want.
Thank you for the quick response, @memsharded! I will try the conf approach you recommend.
Now for a follow-up question, please: How do I get conans.CMake.test to run a subset of tests? With CMake, I can assign one or more labels to tests, and when I run the ctest command I can choose which label(s) I want to include in the test run. But conans.CMake.test doesn't run ctest; it runs cmake --build <builddir> --target test. I'm using conan version 1.52.0.
Well, the cmake.test() wrapper is just a very thin layer, I think you can easily do something like self.run("ctest ...") to run the tests that you want, have you considered that?
I have, but I wonder what might be missed by doing that. In other words, why does cmake.test() not already run ctest?
@memsharded, I tried your recommended approach, and it worked very well -- thanks! But I'm still curious as to why cmake.test() runs cmake --build <builddir> --target test instead of ctest.