Skip to content

How do I write unit tests? #5303

Answered by gforsyth
maikelos asked this question in Q&A
Mar 14, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Yeah, this should be documented.

You have to use the XonshImportHook and a bit of meta_path hacking, so you do:

import sys

from xonsh.imphooks import XonshImportHook
from xonsh.execer import Execer

sys.meta_path.append(XonshImportHook(Execer()))

at the top of your test_ file. And the tests can be written in either a .py file or a .xsh file.

Gist here for full example: https://gist.github.com/gforsyth/b07799771dd530ee51ad6bc3068b25bb

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@anki-code
Comment options

Answer selected by anki-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants