conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] Run only unit tests while developing

Open blackk-foxx opened this issue 3 years ago • 5 comments

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?

blackk-foxx avatar Sep 12 '22 23:09 blackk-foxx

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 -c and 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 a conan install and a conan 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. As conan create typically happens more in CI than in developer machines, I'd recommend to let the conan create be the one that specifies the conf value, and not the conan install that 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.

memsharded avatar Sep 13 '22 00:09 memsharded

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.

blackk-foxx avatar Sep 13 '22 16:09 blackk-foxx

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?

memsharded avatar Sep 13 '22 17:09 memsharded

I have, but I wonder what might be missed by doing that. In other words, why does cmake.test() not already run ctest?

blackk-foxx avatar Sep 13 '22 17:09 blackk-foxx

@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.

blackk-foxx avatar Sep 15 '22 16:09 blackk-foxx