Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Make self.dependencies available for test_package #12411

Closed
1 task
uilianries opened this issue Oct 27, 2022 · 6 comments
Closed
1 task

[feature] Make self.dependencies available for test_package #12411

uilianries opened this issue Oct 27, 2022 · 6 comments
Assignees

Comments

@uilianries
Copy link
Member

When creating a test package for a Conan tool package, there are few ways to validate its package.
One way checking its output, like its version and comparing from the package:

def test(self)
    output = io.StringIO()
    self.run("foo --version", env="conanrun", output=output)
    current_version = str(output.getvalue())
    require_version = str(self.deps_cpp_info["foo"].version)
    assert required_version == current_version

In case we try to use self.dependencies["foo"], it returns None.

@franramirez688
Copy link
Contributor

Hi @uilianries!

I think this issue is duplicated. Have a look at conan-io/docs#2794

@memsharded
Copy link
Member

Hi @uilianries

I am afraid, this is not possible in 1.X, by design. The build() and test() methods execute locally, without re-constructing the dependency graph. So it is basically impossible to fill the self.dependencies when they are executing.

The approach would be similar to the one that recipe should use:

  • Access self.dependencies in the generate() method, do whatever is necessary, save the versions in a file, or whatever
  • Access the generated files in the build() and test() methods as necessary

@uilianries
Copy link
Member Author

@franramirez688 @memsharded Thank you both!

@SSE4
Copy link
Contributor

SSE4 commented Oct 30, 2022

how about:

  • add a new toolchain/generator to save self.dependencies information to a .json file
  • add a new helper to reconstruct information from the build/test method

it may look like:

def generate(self):
    from conan.tools.json import JsonDependenciesGenerator
    tc = JsonDependenciesGenerator(self)
    tc.generate()

...

def test(self):
    from conan.tools.json import JsonDependenciesLoader
    dependencies = JsonDependenciesLoader(self)
    if dependencies["tinyspline"].options.cxx:
        # do something 
    

@memsharded
Copy link
Member

I think that checking the dependencies in a test_package, needed to actually navigate the dependencies in the test() method is a smell. The test_package is designed to test the integrity and correctness of the current package, if it has been built successfully, if it packaged all the headers and libs, or the executables, etc. Checking for example a specific option value of a dependency seems a bit too much.

And if an option of a dependency is strictly necessary, it is also possible in just a couple of lines of the generate() method to save it in a json file that test can recover, but serializing the whole dependency graph in a new generator seems also a bit overkill for the purpose, and introduces yet another generator to maintain, document, test, and guarantee stability for the future years, this will not be added unless there would be way more evidence of its need.

@uilianries
Copy link
Member Author

Closing this one as it's duplicated with conan-io/docs#2794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants