Package: universal-test-runner
universal-test-runnerThe Universal Test Runner is a zero-configuration, language-aware way to run unit tests in any project. It installs a command,t, which will determine how to run your test suite (and then run it).If you're working on a JS project, it runs[your package manager here] test. You've runpytestin this folder before?pytestit is. Rust project?cargo testcoming right up. Is also clever about running all yourgomodule tests (regardless of how they're organized). No matter the command, all args are passed directly into the test runner.Currentlysupports 7 languages(and their respective test frameworks). Please open an issue if I'm missing your favorite!InstallationThe easiest way to install is by usingpipx:pipxinstalluniversal-test-runnerYou can also use brew (which will build from source and take a little longer):brewinstallxavdid/projects/universal-test-runnerUsageYou can also clone thedemo repoto play around with the test runner - it's got toy examples to show how tests are run in many languages!Once installed, the commandtwill be available. Run it in a project folder's root and it'll do its best to run your unit tests:% t
-> pytest
=============================== test session starts ================================
platform darwin -- Python 3.11.0, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/username/projects/test-runner
collected 78 items

tests/test_cli.py ...                                                        [  3%]
tests/test_context.py .....................                                  [ 30%]
tests/test_matchers.py ..................................................    [ 94%]
tests/test_runner.py ....                                                    [100%]

================================ 78 passed in 0.08s ================================It passes all arguments and environment modifications down to the chosen test runner:% t -k test_builder --verbose
-> pytest -k test_builder --verbose
=============================== test session starts ================================
platform darwin -- Python 3.11.0, pytest-7.3.1, pluggy-1.0.0
cachedir: .pytest_cache
rootdir: /Users/username/projects/test-runner
collected 78 items / 77 deselected / 1 selected

tests/test_context.py::test_builder PASSED                                   [100%]

========================= 1 passed, 77 deselected in 0.03s =========================It prints the command it's running as part of the output. To disable that behavior, setUTR_DISABLE_ECHOto any value in the environment.If it can't guess the testing method, it will tell you so. Feel free to open an issue to request wider language support!DebuggingThe package also ships a command to surface info about itself:universal-test-runner. It has a few key pieces of functionality:theuniversal-test-runner --versionflag, which prints info about your installed package versiontheuniversal-test-runner debugcommand, which prints info about which matcher would run (and why):% universal-test-runner debug
[universal-test-runner]: checking each handler for first match
[universal-test-runner]:   Checking matcher 01/11: pytest
[universal-test-runner]:     looking for: ".pytest_cache"
[universal-test-runner]:     no match, continuing
[universal-test-runner]:   Checking matcher 02/11: py
[universal-test-runner]:     looking for: "tests.py"
[universal-test-runner]:     no match, continuing
[universal-test-runner]:   Checking matcher 03/11: go_multi
[universal-test-runner]:     looking for: "go.mod" and no arguments
[universal-test-runner]:     no match, continuing
[universal-test-runner]:   Checking matcher 04/11: go_single
[universal-test-runner]:     looking for: "go.mod" or a file named "..._test.go"
[universal-test-runner]:     no match, continuing

...

[universal-test-runner]: no matching test handler. To add a new one, please file an issue: https://github.com/xavdid/universal-test-runner/issuesSupported LanguagesThis list describes how each language behaves (but not the order in which languages are matched; use thedebuggerfor that).Pythonchecks formanage.py(Django)else usespytestif you've runpytestbefore. You'll need to run pytest manually on clean installs beforetwill worklooks for atests.pyfile if notRustcargo testGoif there's aX_test.go, then runs a plaingo testif you pass any args at all, runsgo test your-args-hereotherwise, runsgo test ./...Elixirmix testClojurelein testJavascript/Typescriptif there's apackage.jsonand it has atestscript, runs[package manager] test, where[package manager]is:npmif there's apackage-lock.jsonyarnif there's ayarn.lockpnpmif there's apnpm-lock.yamljustfileuses the JSON api to find atestcommandMakefilelooks for a line that starts withtest:ExercismExercismis a platform for learning new programming languages. It has more than 65 tracks available. The Universal Test Runner supports nearly all of them out of the box using theExercism CLI'sexercism testcommand. Just like this tool, it knows how to run each track's tests and invokes the correct one automatically.Rather than re-implement all of the test commandsexercismcan handle, the runner will invoke the Exercism CLI when run from an exercise directory. This requires version3.2.0of the Exercism CLI installed.fun fact: Iadded the test commandafter it was suggested in theforum threadwhere I announced the Universal Test RunnerMotivationI work in a few languages at a time, so I've actually had aversion of this in my dotfilesfor a while. Also, as I've been doingExercism's #12in23 program, I'mreallyswitching languages. It's nice not to have to re-learn any muscle memory. Plus, increasingly complexbashwas holding me back.Design PhilosophyThe runner itself should need no configuration - it Just WorksIt should pass all arguments through to the underlying test commandIt should have wide language and test runner support; please open an issue if your use case isn't supported!FAQjusterrors when passing CLI argsIf you run with args (liket -k matcher) and see an error fromjustlike:error: Justfile does not contain recipes `-k` or `matcher`.That means yourtestrecipe doesn't accept any options. Make sure it has an*optionsarg that you pass through to your test command:test *options:pytest{{options}}DevelopmentThis section is people making changes to this package.When in a virtual environment, run the following:pipinstall-e'.[test]'This installs the package in--editmode and makes its dependencies available. You can now runtto run tests anduniversal-test-runnerto access help, version, and debugging info.Running TestsIn your virtual environment, a simplepytestshould run the unit test suite. You can also runpyrightfor type checking.Releasing New Versionsthese notes are mostly for myself (or other contributors)Runjust releasewhile your venv is activepaste the stored API key (If you're getting invalid password, verify that~/.pypircis empty)