[{"data":1,"prerenderedAt":329},["ShallowReactive",2],{"project-21003945":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":29,"sentiment":30,"stance_mix":31,"scored_comments":36,"aspects":37,"strip":44,"post_text":45,"what":46,"said":86,"maker_in_thread":198,"shape":207,"grid":211,"attempts":288,"same_week":293,"maker_shows":35,"maker_hidden":321,"reader_version":322,"card":323},"21003945","hypothesis-auto","Python Tests That Write Themselves","title","Show HN: Python Tests That Write Themselves","https:\u002F\u002Ftimothycrosley.github.io\u002Fhypothesis-auto\u002F","timothycrosley.github.io","timothycrosley",1568803966,2019,131,37,348,2195,16,"notable","dev_tools","test generation","library",[24,25,26,27,28],"python testing","property-based testing","hypothesis","pytest","type annotations","curious",-0.114,{"positive":32,"neutral":33,"mixed":34,"critical":35},3,15,1,5,24,{"idea":38,"execution":40,"docs":41,"design":43},{"positive":39,"critical":32},2,{"positive":34,"critical":34},{"positive":42,"critical":42},0,{"positive":42,"critical":34},[32,42,35,32,32,32,32,32,32,42,34,34,42,32,42,35,32,42,42,32,42,32,34,42,32,42,34,42,32,42,32,42,32,34,35,32,42],null,{"problem":47,"audience":57,"pricing":45,"motivation":61,"time_to_build":45,"stack":65,"openness":85,"stage":85,"team_size":85},{"value":48,"source":49,"evidence":50},"Writing Python tests by hand is laborious; it auto-generates tests for functions.","maker",[51,54],{"id":52,"by":11,"text":53},"21007885","It's an extension for hypothesis, and its value is 100% just convenience and accessibility. Really, it's meant to be a sort of gateway to doing full property-based testing, in…",{"id":55,"by":11,"text":56},"21007826","By default, the biggest value from this is catching unexpected runtime exceptions with certain values (the edge cases you don't think of yourself). To get the most value out of…",{"value":58,"source":49,"evidence":59},"Python developers who want property-based testing with low effort.",[60],{"id":52,"by":11,"text":53},{"value":62,"source":49,"evidence":63},"Provide a low-barrier gateway to full property-based testing.",[64],{"id":52,"by":11,"text":53},[66,76,80],{"value":67,"source":49,"evidence":68},"Python",[69,73],{"id":70,"by":71,"text":72},"21008479","rcfox","I like the idea, but I think I would be more comfortable with it generating test files that I could keep beside my other tests. Also, `auto_pytest_magic` doesn't seem to exist.…",{"id":74,"by":11,"text":75},"21006564","Hi @kburman, For cases like that it would be best combined with a mock: ``` @auto_pytest() def test_add(test_case, mocker): mocker.patch('db.call') test_case() ``` Note that this…",{"value":77,"source":49,"evidence":78},"Hypothesis",[79],{"id":52,"by":11,"text":53},{"value":27,"source":49,"evidence":81},[82],{"id":83,"by":11,"text":84},"21008694","> I think I would be more comfortable with it generating test files that I could keep beside my other tests. This is a very interesting idea I might explore more!…","unknown",{"praise":87,"objections":111,"requests":147,"questions":163,"alternatives":175},[88,101],{"value":89,"source":90,"evidence":91},"Good convenience layer over Hypothesis; catches edge-case runtime exceptions.","commenter",[92,93,97],{"id":55,"by":11,"text":56},{"id":94,"by":95,"text":96},"21008310","progval","It's also useful to check the function doesn't crash. I use hypothesis to test a DB abstraction, and it often caught bugs in edge cases I didn't consider: timestamps\u002Ftimezones…",{"id":98,"by":99,"text":100},"21013306","StavrosK","This is great, thank you! Another great example of the benefits strong typing brings.",{"value":102,"source":90,"evidence":103},"Idea of generating tests from runtime observation is appealing.",[104,108],{"id":105,"by":106,"text":107},"21010342","noobiemcfoob","I really like this idea. So, broken out, would the development process look like: 1) Write code 2) Open interpreter (ipython) 3) Import code and call it manually 4) This magic…",{"id":109,"by":11,"text":110},"21011190","I'd use it!",[112,126,133,140],{"value":113,"source":90,"evidence":114},"Amounts to snapshot or fuzz testing that only checks types and crashes, not behavior.",[115,119,123],{"id":116,"by":117,"text":118},"21007604","ebg13","Does this do anything other than assert that functions return the right basic type given extremely basic inputs? Is naive type testing a thing that people actually bother doing…",{"id":120,"by":121,"text":122},"21013401","anonytrary","This sounds like snapshot testing. It is the responsibility of the person to browse the produced snapshots to ensure they are correct.",{"id":124,"by":117,"text":125},"21008249","> By default, the biggest value from this is catching unexpected runtime exceptions with certain values (the edge cases you don't think of yourself). So it's a fuzzer?",{"value":127,"source":90,"evidence":128},"Generated coverage may give false confidence.",[129],{"id":130,"by":131,"text":132},"21011573","ben509","On one job, I had to disable code coverage for a whole suite of tests that were simply making calls and completely ignoring the results. I know, coverage is Yet Another Metric,…",{"value":134,"source":90,"evidence":135},"Edge cases found by generated inputs may be irrelevant and need constraints.",[136],{"id":137,"by":138,"text":139},"21020909","somada141","While I had really liked the idea of hypothesis in Python I found that the edge-cases it was uncovering were the ones that were obviously gonna break but at the same time cases I…",{"value":141,"source":90,"evidence":142},"Side-effecting functions like DB calls are hard to test without mocks.",[143],{"id":144,"by":145,"text":146},"21004288","kburman","Nice concept but does it work with real-world application. I failed to understand how will it work with methods like `authenticate_user(user)` or `load_permissions_from_db(user,…",[148,152],{"value":149,"source":90,"evidence":150},"Generate standalone test files that can be kept with other tests.",[151],{"id":70,"by":71,"text":72},{"value":153,"source":90,"evidence":154},"Use trailing underscore for parameters instead of leading underscore.",[155,159],{"id":156,"by":157,"text":158},"21007783","iandanforth","I like this idea. One piece of feedback, a parameter with a leading underscore feels very odd. In python I interpret leading underscores to indicate the programmer thinks of this…",{"id":160,"by":161,"text":162},"21008571","duckerude","I believe Raymond Hettinger now considers that a mistake, and wishes he had gone with a trailing underscore (param_) instead. A trailing underscore is just as unlikely to lead to…",[164,171],{"value":165,"source":90,"evidence":166},"What advantage over Hypothesis' native inferred strategies?",[167],{"id":168,"by":169,"text":170},"21007656","hchasestevens","This is neatly packaged, but it's not immediately clear what advantages it has over Hypothesis' native offerings for accomplishing this? (…",{"value":172,"source":90,"evidence":173},"Does it only check return types?",[174],{"id":116,"by":117,"text":118},[176,180,187],{"value":177,"source":90,"evidence":178},"Hypothesis inferred strategies and from_type",[179],{"id":168,"by":169,"text":170},{"value":181,"source":90,"evidence":182},"Snapshot testing",[183],{"id":184,"by":185,"text":186},"21010305","rcap","This is basically what they call snapshot testing",{"value":188,"source":90,"evidence":189},"VCR and MonkeyType",[190,194],{"id":191,"by":192,"text":193},"21012161","Izkata","Possibly vcr [0], except that's for mocking out APIs in unit tests. There's a whole bunch of ports to other languages midway down the page. [0] https:\u002F\u002Fgithub.com\u002Fvcr\u002Fvcr",{"id":195,"by":196,"text":197},"21010736","OJFord","Instagram created 'MonkeyType' to do something similar for type annotations. A lower barrier way of trying this out could be to run MonkeyType in combination with OP's…",{"comments":199,"answered":200,"key":201},11,4,[202,203,204],{"id":109,"text":110},{"id":55,"text":56},{"id":205,"text":206},"21008292","Yes! A smart one though, that limits itself to the type constraints you've specified to avoid redoing the work of your type checker.",{"commenters":208,"max_depth":35,"maker_replies":199,"first_comment_mins":209,"lifespan_hours":210},22,56,35,[212,216,218,220,223,226,227,228,231,234,236,238,239,240,241,242,244,246,248,251,252,253,255,256,258,261,263,266,269,270,273,275,277,279,282,284,287],[213,42,32,214,215,42],"21010278","project\u002Fneutral\u002Fidea","mrfusion",[184,42,42,217,185,42],"commenter\u002Fneutral\u002Fidea",[105,42,35,219,106,42],"project\u002Fpositive\u002Fidea",[221,42,32,214,222,42],"21013849","ACow_Adonis",[224,42,32,214,225,42],"21010591","ryall",[191,42,32,214,192,42],[195,42,32,214,196,42],[229,42,32,214,230,42],"21012133","westurner",[232,42,32,214,233,42],"21011145","knubie",[109,42,42,235,11,34],"project\u002Fpositive\u002Fnone",[120,42,34,237,121,42],"project\u002Fcritical\u002Fidea",[116,34,34,237,117,42],[55,34,42,214,11,34],[124,34,32,214,117,42],[205,34,42,219,11,34],[94,34,35,243,95,42],"project\u002Fpositive\u002Fexecution",[70,39,32,245,71,42],"project\u002Fmixed\u002Fexecution",[83,39,42,247,11,34],"maker\u002Fneutral\u002Fdocs",[249,39,42,250,71,42],"21009433","commenter\u002Fneutral\u002Fnone",[168,32,32,214,169,42],[52,32,42,214,11,34],[254,32,32,214,196,42],"21010794",[130,200,34,237,131,42],[257,35,42,247,11,34],"21006651",[259,35,32,247,260,42],"21008215","djaychela",[262,35,42,247,11,34],"21008392",[156,264,34,265,157,42],6,"project\u002Fcritical\u002Fdesign",[267,264,42,268,11,34],"21007859","project\u002Fneutral\u002Fdesign",[160,264,32,268,161,42],[271,264,42,272,11,34],"21008705","maker\u002Fneutral\u002Fdesign",[274,264,32,268,192,42],"21012189",[276,264,42,272,11,34],"21013715",[278,264,32,268,161,42],"21013759",[137,280,34,281,138,42],7,"project\u002Fcritical\u002Fexecution",[98,283,35,219,99,42],8,[144,285,32,286,145,42],9,"project\u002Fneutral\u002Fexecution",[74,285,42,286,11,34],[289,290],{"id":4,"t":12,"points":14,"comments":15},{"id":291,"t":292,"points":34,"comments":34},"21006485",1568821075,[294,299,304,308,312,317],{"id":295,"name":296,"points":297,"category":298},"20982161","Doka image editor",425,"creative",{"id":300,"name":301,"points":302,"category":303},"21005790","nocsok",343,"web_saas",{"id":305,"name":306,"points":307,"category":303},"20971392","RemoteMore",334,{"id":309,"name":310,"points":311,"category":20},"20985429","Darklang",326,{"id":313,"name":314,"points":315,"category":316},"20995056","ByteVitae",265,"productivity",{"id":318,"name":319,"points":320,"category":303},"21004039","Publisheet",188,false,"v2",{"id":324,"name":5,"line":6,"ai":321,"cat":20,"year":13,"points":14,"comments":15,"rec":29,"s":325,"top":18,"kw":326,"maker":11,"domain":10,"tier":19,"attempts":39,"strip":327,"url":9,"mix":328,"praise":89,"objection":113,"sub":21},21003945,-0.11,[24,25,26,27,28],"3053333330110305300303103010303031530",[32,33,34,35],1793990994955]