Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Can we run PyTest on are packages with this? #635

Answered by rgommers
dreamer-coding asked this question in Q&A
Discussion options

Is it possible to write test cases in Python for a Python extension written language XYZ using something like PyTest to validate the functionality in the extensions using Meson-Python layer?

You must be logged in to vote

Sure. This question isn't very related to meson-python. meson-python lets you install Python packages built with Meson. If that package has pytest-compatible tests, then yes you can run pytest.

The language that a package is written in shouldn't matter here, as long as the package builds fine. E.g., SciPy has extension modules in C, C++, Cython and Fortran. They all have tests written in Python.

Replies: 1 comment · 6 replies

Comment options

Sure. This question isn't very related to meson-python. meson-python lets you install Python packages built with Meson. If that package has pytest-compatible tests, then yes you can run pytest.

The language that a package is written in shouldn't matter here, as long as the package builds fine. E.g., SciPy has extension modules in C, C++, Cython and Fortran. They all have tests written in Python.

You must be logged in to vote
6 replies
@rgommers
Comment options

Generally, yes. But again, the "create Python bindings for the C code is unrelated to meson-python. You'll need to create such bindings with the Python C API (see https://docs.python.org/3/extending/index.html), possibly with the use of a tool like Cython.

Once you have that, you can write pytest tests, and meson-python can be used to package/install.

@rgommers
Comment options

Here is a toy example using the Python C API: https://github.com/mesonbuild/meson-python/tree/main/tests/packages/purelib-and-platlib

And here is one that also uses Cython (the .pyx files): https://github.com/mesonbuild/meson-python/tree/main/tests/packages/complex

@dreamer-coding
Comment options

How about this let's assume I use this to write a Python extinction and the libraries I'm writing this for happen to use wrap files. Does this work?

@dnicolodi
Comment options

How about you read the documentation, try it out, and ask specific questions when you encounter a problem?

@dreamer-coding
Comment options

Sure, I just happened to have the perfect project to try it out for myself.

Answer selected by rgommers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.