<div><a href="http://github.com/198d/sclara">http://github.com/198d/sclara</a></div><div><br></div>I wrote this library based on a thought I had at the TiP BoF this year (hence the name &quot;s(anta)clara&quot;): RSpec for Python (unoriginal idea) written entirely with context managers (original idea, hopefully). I had been writing Ruby for 3 years up until about December of last year and have been writing Python full time since then. What I like most about RSpec is the way you define and organize tests. You end up grouping similar test cases in a sort of hierarchical manner (without resorting to OOP, which I hate the most about writing tests with unittest) and get things like cumulative setup/teardown from parent contexts while producing an english statement that is either true or false after the test is run. These are the main ideas I tried to capture with sclara. Context mangers, at first glance kind of make sense; if you make a quick sketch of what this might look like, you get something like this:<div>
<br></div><div>with description(&#39;Our object under test&#39;):</div><div>  with test(&#39;does something&#39;):</div><div>    assert True</div><div>  with test(&#39;does something else&#39;):</div><div>    assert True</div>
<div>  with description(&#39;when some condition is met&#39;):</div><div>    with test(&#39;acts a specific way&#39;):</div><div>      assert True</div><div><br></div><div>Production test cases that read:</div><div><br></div>
<div>Our object under test does something.</div><div>Our object under test does something else.</div><div>Our object when some condition is met acts a specific way.</div><div><br></div><div>It gets a bit more complicated once you remember how context managers actually work (e.g. delayed execution). My answers to a lot of the questions that will arise when you start thinking about how you&#39;d actually implement this are greenlets and AST manipulation. Check out sclara.runner and sclara.builder for the more interesting parts. You can run the examples like so (from the root of the project):</div>
<div><br></div><div>$ PYTHONPATH=. python examples/test_sclara.py</div><div>$ PYTHONPATH=. python sclara/plugin.py examples/test_simple.py</div><div><br></div><div>There are failures in both as a demonstration of how this interacts with a TestRunner. The first one proves mainly that this is just Python; if you use one of the provided runners you can execute your test files with the Python interpreter (a big goal after looking at a tool like komira for this sort of thing). The latter demonstrates that a nose plugin is possible and probably implies that a py.test plugin is doable to. </div>
<div><br></div><div>Beyond sclara, I&#39;m considering the idea that, more than a testing framework, I stumbled on an interesting pattern for building generic DSLs in Python (more on this soon, hopefully).</div><div><br></div>
<div>Thoughts?</div><div><br></div><div>(I just realized I should start a blog or something...haha)</div><div><br></div>