'How to implement conditional requirements in a conanfile?

We have projects that require different Conan packages during unit tests (i.e. mocks) than during normal compilation. Is there a best practice how to implement conditional requirements in a conanfile for such a use case?

We have tried using switches with environment variables like this:

class project_a(ConanFile):
....
    def requirements()
        if os.getenv('UNIT_TESTING') == 'true':
            self.requires('mock_for_testing/1.0.0@someuser/somechannel
...

But then the requirements for project_a are always changed during unit testing. So also when a project is tested, that consumes project_a.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source