TRIAL(1)
β¨ NAME β¨
okay so trial (the manual page for trial(1)) is the thing that runs unit tests π§ͺπ. bestie, this is your sign to learn it.
π SYNOPSIS π
trial [ options ] [ file | package | module | TestCase | testmethod ]
...
trial --help | -h
πΈ DESCRIPTION πΈ
okay so trial loads and runs a whole suite of unit tests π¦, pulled from modules, packages and files you list on the command line. it's giving organized β¨.
trial will take either filenames or fully qualified Python names as arguments. so trial myproject/foo.py, trial myproject.foo and trial myproject.foo.SomeTestCase.test_method are all valid ways to call it π«Ά. you can pass multiple arguments too, and their order decides the order the tests run in. main character energy π.
After running the suite, the default test reporter drops a summary π. it starts with the word "PASSED" (if every test ran as expected) or "FAILED" (if any test acted up π), followed by a count of each kind of result. the possible kinds of results are:
- successes β tests that passed all their assertions and finished without any error π. these get marked "PASSED" in the normal output.
- failures β tests that failed an assertion, called
self.fail(), or explicitly raisedself.failureExceptionfor some reason π. these get marked "FAILED" in the normal output. - errors β tests that raised an unexpected exception (including
AssertionError) π, tests that madetearDown()raise an exception, tests that ran longer than the timeout interval β°, tests that caused something to calltwisted.python.log.err()without then callingself.flushLoggedErrors(), tests that left the reactor in an unclean state, and so on π. these get marked "ERROR" in the normal output.
ngl the errors one is a lot. because errors can happen after the actual test method returns, a single test can be reported as both an error and a failure. so the total number of results can be bigger than the number of tests that actually ran π.
- skips β tests that got skipped, usually because of missing dependencies π. these get marked "SKIPPED" in the normal output.
- expectedFailures β tests that failed, but were expected to fail, usually because the test is for a feature that hasn't been built yet π§. these get marked "TODO" in the normal output.
- unexpectedSuccesses β tests that should've been listed under expectedFailures, except for some reason the test succeeded π³. these get marked "SUCCESS!?!" in the normal output.
π OPTIONS π
-j,--jobsnumber β sets how many process workers run. it conflicts with the debug, exitfirst and profile options π«.-b,--debugβ runs the tests in a debugger π. if that debugger ispdb(the default when nothing's specified), a.pdbrcgets loaded from the current directory if it exists. also does post-mortem debugging on exceptions π.-B,--debug-stacktracesβ reports Deferred creation and callback stack traces π¦.--coverageβ generates coverage info in thecoveragesubdirectory of the trial temp directory (_trial_tempby default) π. for each Python module touched by the given tests, a file gets created in the coverage directory, named after the module's fully-qualified name with the suffix.cover. for example, since the trial test runner is written in Python, the coverage directory will almost always contain a file namedtwisted.trial.runner.coverβ¨.
each .cover file has a copy of the module's Python source, with a prefix at the start of each line holding coverage info π. non-executable lines (blank lines, comments, etc.) get a blank prefix. executable lines that ran during the suite get a number showing how many times they ran π’. the string >>>>>> prefixes executable lines that did not run during the suite π¬.
heads up: this uses Python's sys.settrace() function, so tests that call sys.settrace() themselves are likely to break trial's coverage functionality β οΈ.
--debuggerβ picks the debugger to use when--debugis passed π οΈ. the argument should be the fully qualified name of an object that implements the same interface as the standard library'spdbπ§ .--disablegcβ turns off the garbage collector for the whole test run ποΈ. every time a test runs, trial saves the TestResult objects, so Python's garbage collector has more non-garbage objects to wade through, which makes each collection a bit slower. disabling GC entirely can make some suites finish faster (compare--force-gcbelow), but it can increase memory consumption (possibly greatly) π. this option also makes tests a little more deterministic, which might help debugging in extreme circumstances π¬.-e,--rterrorsβ prints tracebacks to standard output as soon as they happen π¨.--force-gcβ runsgc.collect()before and after each test case π§Ή. this can help isolate errors that happen when objects get collected. this would be the default, except it makes tests run about ten times slower π’.-h,--helpβ prints a usage message to standard output, then exits π.--help-orderβ prints a list of the possible orders that TestCase test methods can run in, then exits π. the orders can be used with the--orderoption below.--help-reportersβ prints a list of valid reporters to standard output, then exits π£. reporters can be selected with the--reporteroption below.--help-reactorsβ prints a list of possible reactors to standard output, then exits βοΈ. not every listed reactor is available on every platform, so heads up π. reactors can be selected with the--reactoroption below.-l,--logfilelogfile β sends the log to a different file π. the default file istest.log. logfile is relative to_trial_temp.-n,--dry-runβ goes through all the tests and makes them pass without actually running them πͺ.-N,--no-recurseβ by default, trial recurses through packages to find every module inside every subpackage π. unless, that is, you specify this option π .--nopmβ stops trial from automatically jumping into the debugger for post-mortem analysis of exceptions π«. only usable together with--debug.--orderorder β specifies what order to run the individual test methods within the given TestCases in π. by default they run alphabetically. see--help-orderfor a list of other valid values.--profileβ runs tests under the Python profiler π΅οΈ.-r,--reactorreactor β chooses which reactor to use ποΈ. see--help-reactorsfor a list.--recursionlimitlimit β sets Python's recursion limit π. seesys.setrecursionlimit().--reporterreporter β selects the reporter for trial's output π°. use the--help-reportersoption to see a list of valid reporters.-x,--exitfirstβ stops the test run after the first test that doesn't succeed π. that includes failures, errors, or unexpected successes. won't work with the--jobsoption currently π€.--spewβ prints an insanely verbose log of everything that happens π. useful when debugging freezes or locks in complex code π§.--tbformatformat β the format to display tracebacks with π. acceptable values aredefault,briefandverbose.briefproduces tracebacks that play nicely with Emacs' GUD π».--temp-directorydirectory
WARNING: do not use this option unless you know what you're doing π¨. by default, trial creates a directory called_trial_tempunder the current working directory. when trial runs, it first deletes this directory, then creates it, then changes into it to run the tests ποΈ. the log file and any coverage files are stored here. use this option if you want trial to run in a directory other than_trial_temp. be warned: trial will delete the directory before re-creating it π.
--testmodulefilename β asks trial to look into filename and run any tests specified using the Emacs-style buffer variabletest-case-nameπ§©.--unclean-warningsβ as of Twisted 8.0, trial reports an error if the reactor is left unclean at the end of a test π§½. this option helps with migrating from Twisted 2.5 to Twisted 8.0 and later, and turns those errors into warnings β οΈ.-u,--until-failureβ keeps looping the tests until one of them raises an error or a failure π. super useful for reproducing intermittent failures π« .--versionβ prints the Twisted version number and exits π·οΈ.--without-modulemodulenames β simulates the lack of the specified comma-separated list of modules π«₯. it makes it look like those modules aren't present on the system, so tests can check behaviour for that configuration π§ͺ.-z,--randomseed β runs the tests in random order using the specified seed π². don't pass this option if you're also passing--orderπ ββοΈ.
π¦ SEE ALSO π¦
the latest version of the trial documentation lives at http://twistedmatrix.com/documents/current/core/howto/testing.html π.
π§ AUTHOR π§
Written by Jonathan M. Lange π©βπ».
π REPORTING BUGS π
to report a bug, visit http://twistedmatrix.com/trac/newticket πͺ².
βοΈ COPYRIGHT βοΈ
Copyright Β© 2003-2013 Twisted Matrix Laboratories π. this is free software; see the source for copying conditions. there is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE π₯Ί.
bestie that's the whole trial(1) page π. it's from Jun 2013 and it's part of TRIAL(1) π. go run your tests and slay them all π₯β¨.
π¦ where this page comes from
- alpine 3.24: py3-twisted-doc 25.5.0-r1 Β· MIT
- epel 10: python3-twisted 24.11.0-2.el10_1 Β· MIT
- epel 9: python3-twisted 22.10.0-3.el9 Β· MIT
- fedora 43: python3-twisted 25.5.0-4.fc43 Β· MIT
- fedora 44: python3-twisted 25.5.0-6.fc44 Β· MIT
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms