-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[question] How to run python unit tests #16780
Comments
Hi @pasbi Thanks for your questions.
yes, those are standard Conan recipe methods, it should be possible to do what you want.
It is possible, indeed, you can separate the creation of the package, containing only the build, and then move the testing (functional or e2e, that is, external testing, without access to private implementation detail), from a "consumer" job that basically
It is not really necessary to install python things to make them available. You can make them available by adding their path to |
Thanks for your reply.
But that means we'd need to add the unit tests to the package or to create two packages.
But to my understanding, |
I understood that you already had completely separate CI jobs for this, so I thought you had highly decoupled tasks, so having the packaging in the "build" task and the package-consuming in the "test" task wouldn't really be more work than building and testing in the same place.
That was intended for the separate testing in another job. For running building and testing in the same job and recipe, you can do something like: def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
self.run("export PYTHONPATH=<mypath> && ctest ...") Just the idea, not something tested or complete. There are other possible approaches, like you could use an |
Yes I do have separate jobs. But they share build artifacts (GitLab CI).
Thanks for clarification, that really helps a lot. I think I understood the general approach. |
Sounds good, thanks very much for the feedback! Don't hesitate to create new tickets for any further question you might have. |
I think it's better to reopen than creating a new issue because it's very related. @memsharded You said
Yes, I agree, it's possible (and this technique works in my pipeline in practice). In my particular case, the pyd file did not match the module name ( Of course, there are ways to work around this (use I appreciate your feedback.
... would be the cleaner approach (implying we need to ship tests to consumers or build two separate packages in the CI). |
The problem with Python installation is that it is something outside of Conan control, and it is quite problematic in practice. Installing things in Python requires a So beyond the actual place where the |
With "install", I mean what That is, if I want to use the python module, I still need to set the The term "install" is, unfortunately, quite ambiguous. You could argue that this approach in itself is hacky. I'd like to emphasize that my actual problem is solved (I simply |
I see, thanks for the clarification. It makes sense to keep things in the realm of cmake-install and keep away python virtualenvs and python packages installation. If the process happens in
I know it might be possible to do the testing in the |
Hi @pasbi Did you manage to make it work, did you try to implement the above with a local |
The problem was solved using workarounds (i.a., applying pybind/pybind11#415 (comment), copying some stuff around manually and joining building and testing into one CI-job). That is, I guess our main problem is that we haven't fully committed to conan yet but use it as a mere build and test tool (frankly speaking, mostly because we became tired of getting all the dependencies of OpenCV manually on Windows). We have, however, plans to use conan for distributing and testing our proprietary software and we really want to split building and testing again soon™. |
Ok, sounds reasonable at the moment.
yes, that is true, one thing is fetching and using some dependencies, but creating packages, building and testing driven by Conan recipes, etc, requires taking into consideration packaging/install issues a bit earlier on in the process.
Sounds great. Please do not hesitate to create new tickets for any further question or issue you might have. If you also want to connect more directly and talk with us, feel free to reach out ([email protected], social, etc) I think this ticket can be closed by now, thanks very much for the feedback! |
My C++-library has a Python interface.
Consequently, its unit tests are both C++ (googletest) and Python (pytest).
When doing
conan create mylibrary ...
, it builds the library and tests and then attempts to run the tests.That works well for the C++ tests, but the Python tests fail.
Most likely because they require
import mylib
, which is not available becausemylib
has only been built but not yet installed.I'm a bit lost, please head me into the right direction.
build()
andpackage()
plausible?mylib
creates an importable python package, hence this step is required beforecmake.test()
. Do I need to change that (i.e., create a proper python package in the build step) or is there a way to callcmake.test()
aftercmake.install()
?Thanks!
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: