Package: pytest-nodev
pytest-nodev is a simple test-driven search engine for Python code,
it finds classes and functions that match the behaviour specified by the given tests.How does “test-driven code search” work?To be more precise pytest-nodev is apytestplugin
that lets you execute a set of tests that specify the expected behaviour of a class or a function
on all objects in the Python standard library and in all the modules you have installed.Show me how it works in practice.I need to write aparse_boolfunction that robustly parses a boolean value from a string.Here is the test I intend to use to validate my own implementation once I write it:deftest_parse_bool():assertnotparse_bool('false')assertnotparse_bool('FALSE')assertnotparse_bool('0')assertparse_bool('true')assertparse_bool('TRUE')assertparse_bool('1')First, install thelatest version of pytest-nodevfrom the Python Package Index:$pipinstallpytest-nodevThen copy your specification test to thetest_parse_bool.pyfile and
decorate it withpytest.mark.candidateas follows:importpytest@pytest.mark.candidate('parse_bool')deftest_parse_bool():assertnotparse_bool('false')assertnotparse_bool('FALSE')assertnotparse_bool('0')assertparse_bool('true')assertparse_bool('TRUE')assertparse_bool('1')Finally, instruct pytest to run your test on all candidate callables in the Python standard library:$py.test--candidates-from-stdlibtest_parse_bool.py======================= test session starts ==========================
platform darwin -- Python 3.5.1, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
rootdir: /tmp, inifile: setup.cfg
plugins: nodev-1.0.0, timeout-1.0.0
collected 4000 items

test_parse_bool.py xxxxxxxxxxxx[...]xxxxxxxxXxxxxxxxx[...]xxxxxxxxxxxx

====================== pytest_nodev: 1 passed ========================

test_parse_bool.py::test_parse_bool[distutils.util:strtobool] PASSED

=== 3999 xfailed, 1 xpassed, 260 pytest-warnings in 75.38 seconds ====In just over a minute pytest-nodev collected 4000 functions from the standard library,
run your specification test on all of them and
reported that thestrtoboolfunction in the distutils.util module
is the only candidate that passes your test.Now you can review it and if you like it you may use it in your code.
No need to write your own implementation!Wow! Does it work so well all the times?To be honest strtobool is a little known gem of the Python standard library that
is just perfect for illustrating all the benefits of test-driven code search.
Here are some of them in rough order of importance:a function imported is a one less function coded—and tested, documented, debugged,
ported, maintained…it’s battle tested code—lot’s of old bugs have already been squashedit’s other people code—there’s an upstream to report new bugs toit gives you additional useful functionality—for free on top of thatit’s in the Python standard library—no additional dependency requiredBIG FAT WARNING!Searching code with pytest-nodev looks very much like running arbitrary callables with random arguments.
A lot of functions called with the wrong set of arguments may have unexpected consequences ranging
from slightly annoying, thinkos.mkdir('false'),
toutterly catastrophic, thinkshutil.rmtree('/',True).
Serious use of pytest-nodev, in particular using--candidates-from-all,
require running the tests with operating-system level isolation,
e.g. as a dedicated user or even better inside a dedicated container.
TheStarter kitguide documents how to run pytest-nodev safely and efficiently.Project resourcesDocumentationhttp://pytest-nodev.readthedocs.ioSupporthttps://stackoverflow.com/search?q=pytest-nodevDevelopmenthttps://github.com/nodev-io/pytest-nodevDiscussionTo be decided, see issue#15Downloadhttps://pypi.python.org/pypi/pytest-nodevCode qualityContributingContributions are very welcome. Please see theCONTRIBUTINGdocument for
the best way to help.
If you encounter any problems, please file an issue along with a detailed description.Authors:Alessandro Amici -@alexamiciContributors:@calmomau@kr1Sponsors:Licensepytest-nodev is free and open source software
distributed under the terms of theMITlicense.