4

I am currently in the process of introducing Conan.io (Version 1.20.5) to my project.

With Cmake.test(), I am missing the XML testreport that was previously generated by calling ctest -T test directly.

Here is the conanfile.py build() excerpt:

def build(self):
  cmake = CMake(self)
  cmake.configure()
  cmake.build()
  cmake.test() 

Comments:

1.) Defining args to the build() is breaking the build as these args seem to be forwarded to _build(): https://github.com/conan-io/conan/blob/812c8ec8185e24b2bc41fb6e855d35c925526670/conans/client/build/cmake.py#L276

Regards, Christian

chris polzer
  • 3,219
  • 3
  • 28
  • 44

1 Answers1

8

You want to pass an argument to ctest, but Conan calls cmake --build . --target test instead of ctest directly, thus you need to pass as extra argument:

def build(self):
    cmake = CMake(self)
    cmake.configure()
    cmake.build()
    cmake.test(args=['--', 'ARGS=-T Test'])

This will result in the follow command:

> cmake --build '/tmp/foo/test_package/build/878b1b6e2d4cbc82452d014e37c38868584457e8' '--target' 'test' 'ARGS=-T Test' '--' '-j4'

Now you will have the XML file result.

Regards!

uilianries
  • 3,363
  • 15
  • 28
  • Hm. I am getting ```ConanExeption: Error 1 while executing... ``` the resulting cmake call looks like your example tho. – chris polzer Jan 09 '20 at 12:33
  • 1
    Could you please, add details about your error? Conan version, command line, recipe, log, ... My example works perfectly for a regular recipe – uilianries Jan 09 '20 at 14:23
  • The proposed solution works only on linux, but errors on Windows `MSBUILD : error MSB1008: Only one project can be specified. Switch: ARGS=-T Test `. Is there a Windows alternative? – Suluvai Feb 07 '20 at 00:27
  • Did you try by passing with quotes? `ARGS="-T Test"` – uilianries Feb 07 '20 at 11:02
  • I successfully get the xml report generated. However, it lies in the build folder temporarily created in my conan local cache. How can we programmatically get it from this location ? – vdsbenoit Aug 31 '22 at 16:34