mojo-pytest: Mojo test runner and pytest plugin

GitHub
GitHub - guidorice/mojo-pytest: Mojo test runner, pytest plugin (ak...
Mojo test runner, pytest plugin (aka pytest-mojo). Contribute to guidorice/mojo-pytest development by creating an account on GitHub.
15 Replies
Jack Clayton
Jack ClaytonOP8mo ago
By @guidorice
guidorice
guidorice7mo ago
Thanks @Jack Clayton ! I was actually thinking of archiving mojo-pytest, because now mojo has mojo test . 🎉 that seems new- when did that land? v24 I guess. Also there is a nice docs section here: https://docs.modular.com/mojo/tools/testing Let me know if anyone thinks mojo-pytest is still of any use? cc @Leandro Leites
Testing | Modular Docs
Testing Mojo programs.
Leandro Leites
Leandro Leites7mo ago
Oh that is so great, love the implementation! @guidorice maybe we could rethink mojo-pytest to use this new tooling, being able to run inside pytest has many benefits, think about VsCode test UI integration for instance. In the future you could have a Python project with a small portion of it written in Mojo and you would like to run all the tests (Python + Mojo) with the pytest command, then pytest-mojo would do the trick for you 😎
guidorice
guidorice7mo ago
@Leandro Leites good point! I think mixed python + mojo codebase are going to very common. 👍
toasty
toasty7mo ago
I’ve been using mojo pytest to run tests on all my projects for months now! Great project 🙏🏾
guidorice
guidorice7mo ago
Thanks @toasty
guidorice
guidorice7mo ago
GitHub
Add support for mojo v24.4 · Issue #17 · guidorice/mojo-pytest
The current example/ project does not run with mojo v24.4, it simply needs a couple of simple patches because of changes in the String api, (use str() instead) and also where there are SIMD compari...
guidorice
guidorice6mo ago
Hi all, I released mojo-pytest v24.4 which is compatible with mojo 24.4. It's a redesigned plugin which wraps mojo test and I think it's simpler to use as well. There are some breaking changes, so please do check out the Readme. https://github.com/guidorice/mojo-pytest
GitHub
GitHub - guidorice/mojo-pytest: Mojo🔥 language test runner plugin f...
Mojo🔥 language test runner plugin for pytest. (aka pytest-mojo) - guidorice/mojo-pytest
guidorice
guidorice6mo ago
Hey mojo-pytest users, here is a performance tip with the new v24.4 package: https://github.com/guidorice/mojo-pytest/wiki#2024-07-17-here-is-a-performance-tip
GitHub
Home
Mojo🔥 language test runner plugin for pytest. (aka pytest-mojo) - guidorice/mojo-pytest
guidorice
guidorice4mo ago
Update the docs and the CI script to use mojo v24.5 https://github.com/guidorice/mojo-pytest
GitHub
GitHub - guidorice/mojo-pytest: Mojo🔥 language test runner plugin f...
Mojo🔥 language test runner plugin for pytest. (aka pytest-mojo) - guidorice/mojo-pytest
EzRyder
EzRyder2mo ago
Hi @guidorice! I'm using magic to manage my Mojo environment, and it seems like I should be able to add pytest-mojo as a dependency, but it's not working as expected. In short, magic cannot find pytest-mojo in PiPy. Error message:
× failed to solve the pypi requirements of 'default' 'linux-64'
├─▶ failed to resolve pypi dependencies
╰─▶ Because pytest-mojo was not found in the package registry and you require pytest-mojo>=24.5,<25, we can conclude that your requirements are
unsatisfiable.
× failed to solve the pypi requirements of 'default' 'linux-64'
├─▶ failed to resolve pypi dependencies
╰─▶ Because pytest-mojo was not found in the package registry and you require pytest-mojo>=24.5,<25, we can conclude that your requirements are
unsatisfiable.
Here's an excerpt from my mojoproject.toml file. What am I missing?
[pypi-dependencies]
pytest-mojo = ">=24.5, <25"
[pypi-dependencies]
pytest-mojo = ">=24.5, <25"
So what I did was to install pip by adding it to the mojoproject.toml file, then manually installing pytest-mojo from the command line. pip install git+https://github.com/guidorice/mojo-pytest.git pytest now finds my Mojo tests. Is this workaround the 'proper' way to do it when using magic?
guidorice
guidorice2w ago
Hi @EzRyder sorry for the late reply! pytest-mojo is not actually published to pypi yet, nor any other package repositories. So installing it from source via github is the way to go. it seems like magic should be able to support this without mixing in the pip commandline calls! but I'm not sure- will let you know if I discover any better way.
guidorice
guidorice2w ago
Updated and tested the package with mojo v24.6! https://github.com/guidorice/mojo-pytest
GitHub
GitHub - guidorice/mojo-pytest: Mojo🔥 language test runner plugin f...
Mojo🔥 language test runner plugin for pytest. (aka pytest-mojo) - guidorice/mojo-pytest
EzRyder
EzRyder2w ago
I couldn't get it to work again, so I've been using mojo test which seems to be working both on the command line and from the test interface within VS Code. Your plugin allowed me develop several tests before Mojo/Magic evolution broke things. Thanks for getting back with me and Merry Christmas! 🎄
guidorice
guidorice7d ago
ok glad you found a workaround. mojo-pytest now actually wraps mojo test for mojo files. it mainly would be useful for mixed python + mojo codebases to allow a unified test runner. happy holidays to you as well!

Did you find this page helpful?