Latest / Talk Python To Me / #63: Validating Python tests with mutation testing
Transcript
- 0:00Do you think it's a good idea to test your software?
- 0:01Do you write unit tests or other automated verification for your code?
- 0:05I think most of us do these days.
- 0:07But a key question is, how do you know whether your tests efficiently verify your code?
- 0:12And the standard answer is code coverage.
- 0:14But there's a big difference between executing code,
- 0:17which is what code coverage measures, and truly verifying it.
- 0:20On this episode, we'll talk with Austin Bingham.
- 0:23He created a mutation testing framework for Python
- 0:26that goes beyond code coverage to actually perform this verification.
- 0:30It's a fresh and powerful idea.
- 0:31I hope you enjoy it.
- 0:32This is Talk Python To Me, episode 63, recorded June 15, 2016.
- 0:37Developers, developers, developers, developers.
- 0:41I'm a developer in many senses of the word
- 0:44because I make these applications, but I also use these verbs to make this music.
- 0:48I construct it line by line, just like when I'm coding another software design.
- 0:53In both cases, it's about design patterns.
- 0:56Anyone can get the job done.
- 0:58It's the execution that matters.
- 0:59I have many interests.
- 1:01Sometimes you can flip it.
- 1:02Welcome to Talk Python To Me, a weekly podcast on Python,
- 1:05the language, the libraries, the ecosystem, and the personalities.
- 1:08This is your host, Michael Kennedy.
- 1:10Follow me on Twitter, where I'm @mkennedy.
- 1:12Keep up with the show and listen to past episodes at talkpython.fm,
- 1:16and follow the show on Twitter via at Talk Python.
- 1:19This episode is brought to you by Hired and SnapCI.
- 1:22Thank them for supporting the show on Twitter via at Hired underscore HQ and at Snap underscore CI.
- 1:29Hey, everyone.
- 1:30We have an interesting deep dive into the world of Python testing and Python internals today.
- 1:35Before we chat with Austin about mutation testing and his Python library called Cosmic Ray,
- 1:39I have a few goodies to give away to a lucky couple of listeners.
- 1:42First, Austin and his co-author Rob are giving away a copy of their book, The Python Apprentice,
- 1:48as well as two free passes to their online Python course.
- 1:51As always, just visit talkpython.fm and make sure you're a friend of the show to be eligible to win.
- 1:56I'll pick three lucky winners next week.
- 1:58Now, let's meet Austin.
- 2:00Austin, welcome to the show.
- 2:02Thanks, Mike. I'm really glad to be here.
- 2:04Yeah, I'm super excited to share this mutation testing idea that you've sort of manifested in Python.
- 2:10That's really cool.
- 2:11We'll talk a lot about that.
- 2:12Before we get into it, though, what's your story?
- 2:14How did you get into Python and programming?
- 2:15Well, how I got into programming was when I was quite young, I guess, around 10 years old.
- 2:20We had a computer around the house, and it was an old IBM AT or something along those lines.
- 2:27I forget exactly the model.
- 2:29And it could be programmed in BASIC, and that's really caught my attention.
- 2:32My parents got me some magazines and so forth that taught me how to do more complicated things than I could figure out on my own.
- 2:39And it sort of took off from there.
- 2:40Python, I have tried to figure out where I first started using Python.
- 2:45And to be honest, I'm not entirely sure.
- 2:47I think it was around in graduate school, though.
- 2:49So this would have been in the late 90s.
- 2:52Nice.
- 2:53What did you study in grad school?
- 2:53That was software engineering.
- 2:55This was at University of Texas at Austin.
- 2:57And we were doing all sorts of stuff related to artifact traceability in large-scale software systems.
- 3:03And somewhere in there, Python showed up for a build system or something along those lines, and it really caught my attention.
- 3:10And it sort of started there and grew and grew with my career.
- 3:13It has shown up everywhere since then to larger and larger degrees.
- 3:17So it's something that I've really enjoyed using for the past, I guess, 20 years at this point or so.
- 3:22Yeah, that's definitely a while.
- 3:24That's almost from the beginning, right?
- 3:25Not quite, but it's pretty close.
- 3:27Yeah, not quite the very beginnings, yes.
- 3:28But it's been a long time, yeah.
- 3:29Yeah, yeah.
- 3:30Awesome.
- 3:30So we were in Oslo together, Norway, last week with a bunch of other speakers and developers at the NDC, the Norwegian Developer Conference there.
- 3:41And I would say that you and I were the guys carrying the Python flag, if you will, right?
- 3:48Yes.
- 3:48We were kind of the Python guys in the sea, among other types of folks, right?
- 3:53Yes.
- 3:54That's very true.
- 3:56I mean, traditionally, Python doesn't have a large footprint at that conference.
- 4:00And so you and I definitely were the diplomats, I think, the ambassadors for Python.
- 4:06But I was surprised at how much interest there was in it among the other delegates.
- 4:10A lot of people have some glancing experience with it, and they were, I think, interested to see or to learn more about it.
- 4:17So I think it's a growing topic of interest, even at not traditionally Python-heavy conferences and venues.
- 4:24Yeah.
- 4:25Yeah, I've done Python talks at several conferences that were, I would say, decidedly not Python conferences.
- 4:31And they've been received really, really well.
- 4:33And I think it's just one more manifestation or one more piece of evidence that Python is really a growing ecosystem.
- 4:40Yes.
- 4:41Yeah, very much so.
- 4:42And it's just gaining in popularity every year.
- 4:44It's incredible.
- 4:46Yeah, it is, I say this a lot on the show, but it's amazing to me that, like, the language grew at a pretty respectable but not insane growth rate for a really long time.
- 4:57It kind of germinated and then, you know, just caught fire in the 2000s.
- 5:01It's cool.
- 5:02Yeah.
- 5:04Now is the time for Python, yeah.
- 5:05It is definitely the time.
- 5:06So, well, the reason I brought up NDC is you had a really cool presentation there on this concept, which is a general programming concept.
- 5:15It's available in Java and maybe some other languages.
- 5:18I'm not sure.
- 5:19But called mutation testing.
- 5:21So I've done a lot of unit testing and other kinds of testing.
- 5:24I've heard of genetic algorithms.
- 5:26So maybe it's genetic algorithms.
- 5:28I actually know, seeing the talk, I know that it's not necessarily.
- 5:32Why don't you tell us what mutation testing is?
- 5:34I thought it was really interesting, and I wanted to share it with the audience.
- 5:37Sure, sure.
- 5:38Mutation testing is, you can think of it in some sense as a test for your tests.
- 5:43The main goal of mutation testing is to gauge the effectiveness of your existing tests.
- 5:49So if you take the sort of theoretically perfect standpoint that you have a test suite that tests 100% of your functionality, at least in principle,
- 5:58then mutation testing can tell you if your test suite actually does test your functionality.
- 6:03You can find holes in your test system, and it can also help you find code in your code base that isn't tested, and maybe you can just be removed because it doesn't actually contribute to any real functionality.
- 6:14So mutation testing, as you said, has nothing to do with genetic algorithms.
- 6:19It doesn't try to search out failing test cases or something.
- 6:24It's a very dumb algorithm.
- 6:25It systematically makes small modifications.
- 6:28It's kind of exhaustive, right?
- 6:29Exactly.
- 6:30It's an exhaustive, brute force search through a pretty large space to try to just trick your tests into passing a mutant.
- 6:39I mean, the basic idea is that you make these very small changes to your code base and then run your test suite.
- 6:46And if your test suite passes, then we say that the mutant test survived, and this is what you don't want.
- 6:51This means that your test suite is incapable.
- 6:53It doesn't have the fidelity for detecting the change you've made, which we consider an error.
- 6:57Okay.
- 6:58So before we get into that, though, you said something that I thought was interesting.
- 7:03You said you have 100% code coverage, and yet your tests are not doing their thing.
- 7:07So I think there's like layers of, or levels rather, of sort of verifying your test.
- 7:14Like you're writing tests.
- 7:15That's level one.
- 7:16You have tests.
- 7:17They exist.
- 7:17It's an existing thing.
- 7:19Yeah.
- 7:19Step two or level two of enlightenment would be you have a significant amount of code coverage.
- 7:26Because without code coverage, you can have like 1,000 tests, but they could all be about some small, useless part of your app.
- 7:32And the important core section might actually not be tested.
- 7:35But this supposes you're kind of, you're at level two enlightenment, right?
- 7:39You have tests.
- 7:40You have good, maybe not 100%, but you have pretty solid code coverage.
- 7:44And now you want to say, is this actually, there's a difference between executing code and verifying code, right?
- 7:51Right.
- 7:51And this is a really important distinction that mutation testing gets to the heart of, which is, as you say, you could have 100% coverage in the sense that your test suite causes 100% of your instructions to be executed, however you define that instruction set.
- 8:07But it doesn't tell you whether or not, traditional coverage doesn't tell you whether or not your tests are verifying the functionality.
- 8:15So you could have a glaring defect in your program that your test suite is exercising, but not actually verifying.
- 8:24And mutation testing goes to the next level and tries to tell you if your test suite is actually verifying functionality, if it's capable of detecting actual errors.
- 8:34And if it's not, then we say that you need a more powerful test suite.
- 8:37That's kind of the whole point of mutation testing.
- 8:40It's this sort of adjunct to an existing test suite.
- 8:44And just to add on that, I mean, this question of 100% coverage, no matter how you slice it, is a really hard thing for most projects to have.
- 8:52In fact, most projects in the world don't have anything close to 100% coverage.
- 8:57But mutation testing can still be useful, even with systems that don't have 100% coverage.
- 9:02It just is going to throw up a lot of, initially at least throw up a lot of flags telling you that you have problems where you just don't have tests yet.
- 9:10It's not a technique that can just be used on systems that have 100% coverage already.
- 9:16I guess that's my point.
- 9:18That's good, because that means it would have been excluded from quite a wide bit of code out there, right?
- 9:23Yeah.
- 9:23Nobody would be able to use it.
- 9:24Yeah, that's the truth.
- 9:26Yeah.
- 9:26Right.
- 9:26Okay.
- 9:27So there's some really cool ideas here.
- 9:30You're talking about a mutant.
- 9:31This is the idea of changing your program, introducing some mutation.
- 9:36It's just some, almost randomly find a spot and make a change and see what the effect is.
- 9:42Because theoretically, you should be able to detect this change which broke something, presumably by changing it, right?
- 9:49Yeah, that's exactly the case.
- 9:52The mutations we're talking about, the modifications we're talking about are typically very, very small.
- 9:56And so the kind of canonical example that it's always trotted out is replacing a relational operator.
- 10:03So if I have some line of code that's, you know, X is less than one, I could change that.
- 10:08The mutation would be to change that to X is greater than one, for example, and then make that one small change and then run the test suite again.
- 10:15So these changes are very, very small, but the point is that the changes should all, in principle, be detectable by a sufficiently powerful test suite.
- 10:23Okay.
- 10:24That sounds like that would be true most of the time, but I think there might be some cases where it might not be detectable.
- 10:32Before we get into that, though, I just want to clarify for the listeners, you're not the one doing the mutations, right?
- 10:39Like, as a developer, that's not you.
- 10:42Correct.
- 10:42The whole point of a mutation testing tool is that it will do the hard work, the boring work of plowing through your code, finding the places that can potentially be modified, modifying them, and then running your test suite.
- 10:54So in principle, you should be able to point the tool at your code, tell it what your test suite is, and then walk away for probably a very long time and then come back to get your results.
- 11:07And, yeah, you don't – it takes away all the drudgery associated with that and actually gives you some really interesting results typically in the end.
- 11:15Yeah, that is really cool.
- 11:16So maybe we could think about, like, what does the mutation testing tell us?
- 11:21Because sometimes you might make a change and your code will then fail the test, right?
- 11:27So if you were testing that, I select a user and it's equal – the count of users I got back was one, and you change that to not equal, for example, your framework changes it to not equal.
- 11:37Obviously, that test would fail, but it could also change things that I don't detect up.
- 11:42I don't detect.
- 11:43Yes, that's true.
- 11:44You can have a result where your test suite passes a mutant, and then you go examine the code, and you realize that there's really no way to write a realistic test that would detect that change.
- 11:58And this is a class of mutants that, if you read the literature, is called an equivalent mutant.
- 12:03And an equivalent mutant is exactly that, a mutant that is functionally equivalent.
- 12:07It's still a mutant.
- 12:08It's been changed, but it's still functionally equivalent to the original program.
- 12:13And for some reason or the other – and this is a very language-specific thing – but for some reason or the other, you simply cannot detect it.
- 12:19And this is one of the really tricky, difficult aspects of mutation testing is ferreting out and somehow avoiding these equivalent mutants.
- 12:28Yes.
- 12:28Yeah, that's interesting.
- 12:30So obviously, if we mutate it and then the test fail, that's an upvote for our test, right?
- 12:37We've made a change to the code.
- 12:38We reran the test.
- 12:40The test said, your code has changed.
- 12:42It's no longer good.
- 12:43But then sometimes it might not come back.
- 12:47Is it possible that if, like, you change some kind of, like, while loop condition, it could just go forever?
- 12:53That's entirely possible.
- 12:54And this is yet another class of complexities that we have to deal with in mutation testing.
- 13:00These mutants that – the great example, the canonical example is what you said.
- 13:06They go into an infinite loop.
- 13:07So if I change, for example, one mutation would be to change a break to a continue.
- 13:12And if you do that, then you typically create a situation where an infinite loop is very, very likely because you've taken a place where your code is in the exit condition and then where it wants to break.
- 13:23And you said, no, don't break.
- 13:24Continue the loop.
- 13:25And it's going to stay in the exit condition and just kind of continue forever.
- 13:28So that kind of mutant falls into the category that we call incompetent.
- 13:34And I guess I should back up and say there are sort of three main categories for mutants.
- 13:39After you've run your test suite, you have some results.
- 13:41You talked about just a second ago where the test suite fails.
- 13:47And we say that in that case, your test suite has killed the mutant.
- 13:50Your test suite has failed, indicating that it knows that you've made a change.
- 13:53The other broad category is that your mutant survives.
- 13:56That is, your test suite passes.
- 13:58And this is where we start to look for weaknesses in our test suite.
- 14:01The third sort of smaller category is this category of incompetent mutants.
- 14:06Most incompetent mutants fail immediately by throwing an exception or failing to compile or doing something along those lines,
- 14:13something catastrophic that prevents them from actually even being run under the test suite.
- 14:18And these, we still count these as killed.
- 14:20These go in the checkbox category.
- 14:22This is good.
- 14:23But there are some incompetent mutants that do things like, you say, just run forever or maybe run for a very, very, very, very long time,
- 14:30so long that we don't really want to try to see if they stop.
- 14:34So this area is a difficult one.
- 14:38It's one that you have to address on a practical level when you develop tools to do mutation testing, this problem of incompetence.
- 14:46And, you know, you start looking into the theory of detecting incompetent mutants,
- 14:51and you run smack into Alan Turing's famous proof about the halting problem,
- 14:55saying that you cannot look at a program and determine a priori if it's going to stop running at some point in the future.
- 15:02And that's the problem you face with incompetent mutants and mutation testing.
- 15:06Yeah.
- 15:06There's not even much reasoning about it because it's just a brute force method anyway.
- 15:10Correct.
- 15:11Yeah.
- 15:11Yeah, that's a big challenge.
- 15:12Can you give me some idea of, like, how frequent that category shows up?
- 15:18Is that, like, 0.1%, 5%, 10%?
- 15:22That's a tough question to answer on a global scale because, I mean, I obviously haven't run mutation testing on every program.
- 15:29But in my experience, it's a relatively small amount.
- 15:33I mean, less than 1% of mutations, far less than 1% of mutations become incompetent.
- 15:39They're not a huge problem in practice because the strategies we use to deal with them are really simple,
- 15:44which basically what we do is we timeout.
- 15:47We establish, using one method or another, a timeout for your test suite.
- 15:51And if it takes longer than the timeout, then we just count that as incompetent.
- 15:54We say that mutant is in an infinite loop or in a huge loop, and we're going to say that it didn't get to run.
- 15:59If you consider performance part of your feature set, maybe it's failed anyway, right?
- 16:03Right.
- 16:04Yeah, it's clearly problematic at that point.
- 16:07Okay, interesting.
- 16:08And you actually had two ways of timing out.
- 16:11Like, you could just say, well, we're never going to run tests more than five minutes.
- 16:14But you had a cool thing to do with baselines as well, right?
- 16:17In the tools that we have right now for doing mutation testing in Python, the approach we take is to, well, as you said, one way is let the user provide a timeout.
- 16:27They can just provide an absolute timeout, and we'll honor that.
- 16:29Or we can run the test suite over unmutated code and time that and use that as a baseline and then let the user provide some multiplier, say, two or three.
- 16:40And then if a mutant's test suite takes longer than n times the baseline timing, then we consider that an incompetent mutant and we kill it off.
- 16:48So this is our really simple but generally very effective approach to dealing with the halting problem in practice.
- 16:55Yeah, it's way easier than proving it, right?
- 16:57Right, yeah.
- 16:59So that would be really difficult to do.
- 17:00Yeah, nice.
- 17:02Okay, so we have obviously the case where the mutant is killed.
- 17:05We have this incompetent mutant, which we kind of can't really deal with.
- 17:10But then we have the more challenging case.
- 17:13It's maybe the interesting case, you would say, where you've changed the code, you run the test, and the tests all still pass.
- 17:21Right?
- 17:22So there's a couple of conclusions you could draw from this, yeah?
- 17:24Well, yeah.
- 17:26If you've made a mutation and the tests still pass, then you have a couple of things to look into.
- 17:35One possibility, the standard thing that happens in that case is that you just don't have enough tests.
- 17:40You need more or better tests because you have some change that was undetected by your test suite.
- 17:45The other very common, the less common but still quite common case is that you have code in your program that doesn't need to be there anymore.
- 17:53It's extra code that doesn't contribute to any functionality.
- 17:56So your test, in that case, your test suite is perfectly good because it's testing the things it needs to be testing,
- 18:02the important functionality of your program.
- 18:05But you've got bits of code that can be mutated but aren't being tested, so you should yank those bits of code out.
- 18:10If you view code as a liability rather than something important to keep around, you can just get rid of it at that point.
- 18:16The third possibility, and this is really a subcategory of the first, is that we come back to this notion of equivalent mutants.
- 18:23Mutants that they have been changed.
- 18:26Our test suite hasn't detected them, but there's no practical way to write a test for those.
- 18:31And there's all sorts of interesting examples of these.
- 18:35They're a bit difficult to describe, perhaps, purely without showing some code.
- 18:42Speaking of showing, all the videos of the sessions, including yours and mine from NDC, will be online shortly.
- 18:49And so as soon as they are online, I'll put a link to your presentation so people can go back and see it.
- 18:55But yeah, it is tough to talk about code examples on audio, right?
- 19:00Yeah, it's quite difficult.
- 19:01But for Python, I think I could probably describe the Dunder main example.
- 19:06Yeah, go for it.
- 19:08So one equivalent mutant that, in retrospect, is quite obvious, but I hadn't really anticipated, is the standard idiom in Python of using Dunder name equals Dunder main to set up your main block when you're writing a program.
- 19:23But of course, if you've got that in your program and you have any kind of code in that block that can be mutated, the mutation testing suite will mutate that code.
- 19:33But of course, that block is never executed in a test because it's not accessible inside a test because Dunder name does not equal Dunder main in that case ever.
- 19:42So you have this really interesting case where you have this whole body of code that's really important to your program in a way, but that cannot be tested and never will be tested.
- 19:50So that's the flavor of at least some equivalent mutants.
- 19:55But one of the joys of equivalent mutants is that when you find them, you have these aha moments almost every time because they're surprising, they're interesting, and they kind of make you scratch your head a little bit.
- 20:07And so it's one of the, I guess you might say, strange joys of mutation testing.
- 20:12Yeah, that does sound pretty interesting.
- 20:15It definitely gives you some insight you probably wouldn't normally get.
- 20:30This episode is brought to you by Hired.
- 20:32Hired is a two-sided, curated marketplace that connects the world's knowledge workers to the best opportunities.
- 20:37Each offer you receive has salary and equity presented right up front, and you can view the offers to accept or reject them before you even talk to the company.
- 20:45Typically, candidates receive five or more offers within the first week, and there are no obligations ever.
- 20:51Sounds awesome, doesn't it?
- 20:52Well, did I mention the signing bonus?
- 20:54Everyone who accepts a job from Hired gets a $1,000 signing bonus.
- 20:58And as Talk Python listeners, it gets way sweeter.
- 21:00Use the link Hired.com slash Talk Python To Me, and Hired will double the signing bonus to $2,000.
- 21:06Opportunities knocking.
- 21:08Visit Hired.com slash Talk Python To Me and answer the call.
- 21:16One example that I was thinking of when you were talking about that category is like logging, right?
- 21:21So maybe you've got some test, and it says, if this, then log this thing, else log that.
- 21:27And, you know, would it really make sense to, like, write a test to detect what you're logging?
- 21:32Right.
- 21:32That's a really good point.
- 21:33I mean, most, a large category of equivalent mutants are exactly of that flavor.
- 21:38The changes caused by the mutation are things that you, in principle, could test for, but you never would because there's no reason to do it.
- 21:46There may be no business reason to do it.
- 21:49There may be just no practical reason to do it, depending on what values are driving your project.
- 21:55And so you end up not ever writing tests for those.
- 21:57And one of the challenges of writing mutation testing tools is allowing your user to specify, in some way, shape, or form, that mutations should not be performed on certain bodies of code for various reasons.
- 22:12And this is something that all the tools that do mutation testing have to account for in some way, shape, or form.
- 22:19Okay.
- 22:19So I'm going to hold my question on, like, how you deal with that until we get to your framework.
- 22:24Okay, good.
- 22:25Because that is a really interesting problem, and I want to dig into it.
- 22:30But before we do, like, could you give us some, you know, you talked about the sort of the basic changes, like, if you've got a less than, change that to a greater than.
- 22:39There's a whole variety of different types.
- 22:42There's, like, language agnostic changes.
- 22:44There's changes you can make that affect object-oriented programming.
- 22:47Can you give us, like, a sense of those?
- 22:50Sure, yeah.
- 22:51Yeah.
- 22:51So this is actually one of the areas where there's active research into mutation testing.
- 22:56There's not a huge group of people doing this research, but the research that is going on is, to a large degree, into which kinds of mutations should we be actually performing.
- 23:05So you mentioned that there's some mutations that are language agnostic in the sense that they apply to almost all programming languages you can imagine.
- 23:14And so a typical example would be something like replacing a constant.
- 23:19If you found the constant 4 in your code, the mutation testing suite might change that to 5 or 19 or negative 6 or something like that.
- 23:27So this is, you know, it's an obvious change.
- 23:29I mean, it's a sort of blatant change.
- 23:31It should be obviously testable.
- 23:33And so it's ripe for that kind of thing.
- 23:36But other examples include things like replacing arithmetic operators, removing unary or adding unary operators.
- 23:43We talked earlier about relational operators replacing those.
- 23:46And all of these sort of fall into – they're broadly applicable.
- 23:52You could see them being applied in a functional language or an OO language or any other procedural language, whatever kind of language you happen to be working on.
- 24:01But some research has looked into mutations that are specific to, for example, object-oriented languages.
- 24:06Most – well, not Python, but a lot of object-oriented languages have access modifiers, for example, private, public, protected, and so forth.
- 24:15And so one really clever and interesting mutation is to replace public with private or vice versa, to basically go in and mess with the access modifiers and see if that is detected by the test suite.
- 24:27Often that results in something that can't compile.
- 24:29In C++, for example, if you changed public to private, that would probably break compilation of many programs.
- 24:35But changing private to public, it's hard to say.
- 24:38That's actually very, very difficult to test for.
- 24:41Other examples of OO-specific mutations would include, for example, changing base class order.
- 24:48This is another one that can have really dramatic effects on what your program does.
- 24:54Or in other cases, it can have absolutely no effect whatsoever.
- 24:57So you could see how changing base class order in Python, for example, could have a completely undetectable – almost completely undetectable change to a program.
- 25:07The only way to detect that would be if you had a test that was checking base class order, was checking the MRO for the class.
- 25:12And, of course, nobody's going to write that test.
- 25:15And I'm not advocating that anybody write that kind of test.
- 25:17That's not the kind of code you want to write, that's for sure.
- 25:19Right.
- 25:20It's a complete waste of time.
- 25:21So that's, I think, a fairly enlightening example of the kinds of problems you face doing mutation testing.
- 25:29As elegant and interesting and straightforward as the approach sounds, there are these really difficult, thorny edge cases you have to deal with.
- 25:36Other branches of research into, for example, mutations for functional languages.
- 25:41In the classic example there, a lot of Haskell-like and F-sharp-like languages have pattern matching, for example, on their functions.
- 25:47And changing the order of pattern matching is a common mutation you might perform on a language like that.
- 25:52And that, again, is another area where sometimes changing the order makes a huge difference, and sometimes changing the order makes absolutely no difference.
- 25:59And in those cases, I actually don't know how you would test for them because they're undetectable unless you have introspection and you have reflection capabilities.
- 26:08You actually go in and do the kinds of tests I talked about a second ago that you would never write.
- 26:11So it's a fascinating field to kind of dip your toe into, and the papers are pretty accessible if you want to read about these kinds of things as well.
- 26:20It sounds to me like one of the major challenges that you're going to run into for almost any reasonable-sized program is that it's going to be really slow, right?
- 26:31Because you're looking at basically every permutation of all the operators in, you know, inheritance, methods.
- 26:39There's a crazy number of things in play here, right?
- 26:43That's absolutely true.
- 26:44I think the single biggest practical problem with mutation testing, the single biggest practical roadblock for using mutation testing is that it takes a long, long, long time to do.
- 26:55If you consider the possibility of having, you know, dozens or, you know, 100 operators, you know, kinds of mutations that you might make in your code, and you have a large code base, you know, hundreds of thousands of lines of code is not uncommon in valuable systems.
- 27:12Or even not very valuable systems, for that matter.
- 27:15And then you consider the fact also that a test suite might take a considerable amount of time to run.
- 27:19So you have this triply nested loop of the operators, the places those operators can be applied, and the amount of time it takes to run your test suite.
- 27:27And you're talking about, you know, if you do the math, you can find on some systems that adds up to years.
- 27:31I mean, literally, it's not something you can do on a practical basis for all your code in any way, shape, or form.
- 27:37But there are some strategies that we can apply to try to deal with that.
- 27:42The most basic strategy is simply to parallelize.
- 27:45For all the problems we have with long run times and mutation testing, the saving grace is perhaps that it's embarrassingly parallel.
- 27:51You can run each mutation slash test suite run in a completely separate process, all at the same time if you want to, and it won't affect the results.
- 28:00So you could, in principle, go to Azure or Amazon and rent for five minutes, you know, 10,000 or 100,000 machines or whatever they'll let you get, run all your tests, and then be done with it.
- 28:11But that's not something that is probably economically feasible for most people.
- 28:16So other approaches that there are to dealing with this, well, there's not that many other approaches that I'm aware of.
- 28:23But one is another form of baselining.
- 28:25We talked earlier about baselining for your timeouts, you know, when to kill the test suite and call it incompetent.
- 28:31Another kind of baseline that you can do is to run a full test suite with all your operators over all your code and get those results.
- 28:38And then as you start making changes to your code base, only run the tests that, you know, work and exercise modified code, code that you've changed.
- 28:48And that way you can drastically reduce the scope of the number of tests you need to run.
- 28:54And that drastically reduces the number of operators that get applied, the amount of code space that can be potentially modified, and so forth.
- 28:59Also, you can tell your mutation testing system to only mutate code that was modified.
- 29:04So basically, we're analyzing deltas, analyzing our git diffs, so to speak, and saying only run the tests that we know could possibly have an impact or be impacted by the changes that were made.
- 29:14And this is a heuristic approach to speeding things up because, of course, it's not watertight.
- 29:22You could, of course, make changes to your code that influence the code paths that your tests are now exercising.
- 29:29And if you purely use this kind of baselining for determining which tests to run and what to test, then you'll be missing things.
- 29:36So you have to occasionally do, or at least in principle, you'll be missing things.
- 29:39So you'll have to do occasional rebaselinings to make sure that you've kept up with all of your changes.
- 29:43And it also assumes that you have some way of correlating your tests with lines of code.
- 29:48So this is where mutation testing and traditional coverage analysis tools can come into play, where they can work together.
- 29:57Because now you can say, okay, I take the coverage analysis information.
- 30:00I know which tests exercise which lines of code.
- 30:02I can couple that and kind of compare it to the deltas and determine which tests need to be run by the mutation testing suite.
- 30:09It's basically like an inverted code coverage, right?
- 30:12So if I look at this test, what part of my code in my real app changed or somehow was affected by running this test, right?
- 30:22And so you could just focus on, say, like 10 lines of code or probably way more than that.
- 30:26But focus it in on that area, right?
- 30:29Exactly.
- 30:29That's the point is drastically reduce the space.
- 30:32And I think in principle you could get this down to where you could run things fast enough that you could do it on every commit or bundles of commits rather than once a week or something along those lines, which may or may not be desirable.
- 30:45But it's an interesting goal from a tool developer's point of view.
- 30:48Yeah, it's definitely an interesting goal.
- 30:50Well, one of the things I was thinking of as you said this was, is this a thing that needs to run on, say, every check-in or every time you want to run your test?
- 31:00Because if you have a good set of tests, hopefully your tests are actually catching your bugs.
- 31:06And this feels to me like a validation of your tests rather than it seems like it could theoretically run less often and still be really valuable.
- 31:16I think in practice you're right.
- 31:18It doesn't need to run on every check-in.
- 31:20But if you're working on a team that wants perfect code coverage, for example, and that requires, say you have a policy on a legacy code system that any change you make needs to be backed up by tests, which is a common thing to do with existing legacy systems that are trying to improve their lot in this world.
- 31:36You might have that policy.
- 31:38This is on every commit.
- 31:38Whatever changes you've made need to be backed up by tests.
- 31:41And this is a good way to verify that.
- 31:43Not to verify just that you've made tests, but to verify that the tests you've created actually test the functionality correctly.
- 31:51And so if you can make mutation testing fast enough, you could actually enforce that kind of constraint in a pretty strong way.
- 31:57And that's an interesting thing.
- 31:59Yeah, that is quite interesting because my experience is there's a massive difference among team members on their level of embracing testing and how much they run the test.
- 32:09Like some people are really into it.
- 32:11Some people only run it if there's something making them run it, basically.
- 32:14Right.
- 32:16Yeah, that's very true.
- 32:18And so now you have a new stick to beat people around the head with if you have mutation testing in place.
- 32:23Nice.
- 32:26So let's bring this down to Python.
- 32:28Let's make it concrete.
- 32:29Let's talk about this thing called Cosmic Ray that you created.
- 32:33Okay.
- 32:34Yeah.
- 32:34Cosmic Ray is, as you just hinted, it's a mutation testing tool for Python.
- 32:39I should say it's not the first mutation testing tool for Python.
- 32:42There were a few available when I started writing it, but none of them were work.
- 32:47They didn't quite work the way I wanted or they were unmaintained.
- 32:50And really, this was an interesting project in its own right.
- 32:53So this started out almost as just a fun thing to do.
- 32:56And it turned out to be a really fascinating project all around.
- 32:59But Cosmic Ray is a system for searching through your Python code, finding places to mutate, making those mutations, and then running your test suite.
- 33:11And it's a fairly young project.
- 33:14And it has quite a bit of work left to be done on it.
- 33:17But it has produced some results already.
- 33:19So it's looking quite promising.
- 33:21It's about a year and a half old, I think, at this point.
- 33:25And really, it's only been used by me and a few sort of close, trusted friends.
- 33:29But it's open source.
- 33:31It's on GitHub.
- 33:31And anybody who wants to try it or make contributions or give any feedback is more than welcome and, in fact, encouraged to go take a look at it.
- 33:38Yeah.
- 33:39Yeah, awesome.
- 33:39And I'll be sure to link to the GitHub repo and things like that.
- 33:42And it's on PyPI, of course, right?
- 33:43Honestly, I'm not sure.
- 33:46I think it is.
- 33:47But I don't know the last time I pushed up a version to PyPI.
- 33:50Let me see here.
- 33:52Yes, it is.
- 33:53It is on.
- 33:54It's cosmic underscore ray on PyPI.
- 33:57Woo.
- 33:57Okay.
- 33:57Saved.
- 34:00I guess the interesting parts for a lot of people are going to be how cosmic ray works internally.
- 34:05Yeah, absolutely.
- 34:06There is some really amazing stuff in there.
- 34:09Before we get into that, could you just really quickly, like, tell me, what do I need to do?
- 34:14Like, if I've got some Python app with some tests, you know, I'm using pytest or something like that, like, what are my steps to apply this?
- 34:22The steps are, well, pretty straightforward.
- 34:24Identify the parts of your code that you want to mutation test.
- 34:29Very often you'll have some part of your code that has a good test suite and is heavily, thoroughly tested and is central to the functioning and other parts that aren't.
- 34:38And you can use cosmic ray to divvy out and slice and dice the parts you do and do not want to test.
- 34:44So if you just want to take it for a spin, identify some module that you're interested in.
- 34:49Because you want it to happen in a non-trivial, you know, in a short amount of time, right?
- 34:53Well, that's one of the other reasons.
- 34:54Yeah, you'll get more bang for your buck if you're just trying to test drive this than if you try to run it over.
- 34:58You know, a 10,000.
- 34:59If you want to run this over Django, forget it.
- 35:01It's not going to work.
- 35:01But I mean, not in any practical sense.
- 35:03But if you want to run it over a single module in Django or, you know, some other package, then you'll have more luck.
- 35:09That's been my experience, at least, with it so far.
- 35:11But yeah, you'll need a test suite.
- 35:12Right now, we only support unit tests, the standard library unit tests, and pytest as the test suites we support.
- 35:19But there's a plug-in system for other testing systems.
- 35:22If you feel you need one supported, they're pretty easy to add.
- 35:26Point Cosmic Ray at your module and at your test suite.
- 35:30And you'll pass it a few other parameters, you know, things having to do with timeouts and so forth.
- 35:34And it will build up a work order, you know, basically the list of things it's going to do and put those in a little database.
- 35:39And then you'll need to set up Celery.
- 35:42Celery is a task distribution queue that runs on top of RabbitM queue by default.
- 35:50And this, we use Celery to distribute work out to workers that actually do the mutation, run a test suite, and then send results back.
- 35:57And so you'll have workers sitting on your Celery queue.
- 36:01And then you'll tell Cosmic Ray to run the work order that it's built.
- 36:06And it will start doling out work to these workers and collating the results back into the little database it's got.
- 36:11And that's, I mean, that's the short version of what you need to do.
- 36:15Once you have results back, then you start analyzing them and trying to figure out what Cosmic Ray is telling you.
- 36:20Right, you look at those three categories, you decide what to ignore, what not to ignore.
- 36:24Gone are the days of tweaking your server, merging your code, and just hoping it works in your production environment.
- 36:45With SnapCI's cloud-based, hosted, continuous delivery tool,
- 36:49You simply do a git push, and they auto-detect and run all the necessary tests through their multi-stage pipelines.
- 36:55Something fails, you can even debug it directly in the browser.
- 36:58With a one-click deployment that you can do from your desk or from 30,000 feet in the air,
- 37:03Snap offers flexibility and ease of mind.
- 37:06Imagine all the time you'll save.
- 37:08Thanks, SnapCI, for sponsoring this episode by trying them for free at snap.ci.com.
- 37:14And is there a way to flag it and say, this thing you've detected here, I want to ignore that?
- 37:31Not yet.
- 37:31And this is actually one of the big open areas for development, is how do we let users specify exceptions effectively?
- 37:38How do we let them say, don't make this mutation on this line of code?
- 37:42Or even more coarsely, don't make mutations on this line of code.
- 37:45Because we need that kind of thing because of the problems of equivalent mutants and so forth that we have no real solution to.
- 37:54Right now, there's a thought about the direction to take this in, how to deal with it.
- 37:59If you look at tools like PyLint, they have great systems for putting essentially orders into comments in your code telling PyLint,
- 38:06please don't apply rule such and such to this line of code.
- 38:09We could probably apply the same kind of technique to Cosmic Ray.
- 38:13But I'm not sure yet if that's better than having some extrinsic description of exceptions.
- 38:19It's basically an open question.
- 38:21And if anybody has ideas or wants to take a swing at it, this really is one of the big things that we need to sort out soon.
- 38:28Let's look inside.
- 38:29Basically, you point Cosmic Ray at your module and you say, go shred this thing.
- 38:35And for every shred that you create, go run the unit test, right?
- 38:39That's exactly right.
- 38:41Walk us through the internals there.
- 38:43There's some interesting stuff you're doing.
- 38:44Well, at the core of all of this is the standard library module AST.
- 38:50AST is short for, what's it, acronym for Abstract Syntax Tree.
- 38:54An Abstract Syntax Tree is just a programmatic structure defining a program, the syntax in your source code.
- 39:01When Python parses your source code, it produces an abstract syntax tree.
- 39:05And then you can access this looking at the different nodes in the tree, you know, looking at the different parts of your program.
- 39:10And not just look at them, but you can also change them.
- 39:13So what AST allows us to do in Cosmic Ray is load up your source code.
- 39:18We literally read your source code from your .py file.
- 39:21And we pass it into a parse function, which parses the source code into the abstract syntax tree.
- 39:26And then AST has other components, which allow us to walk down that tree.
- 39:31And if we want to make changes, the details of exactly how it does that, it might be difficult to talk about operators and things like that in too great of detail.
- 39:41Yeah.
- 39:42So, well, basically you get this abstract syntax tree and then you start applying your transformations to it, right?
- 39:50Your mutations, if you will.
- 39:52Yeah.
- 39:52Well, that's the fundamental idea, yes.
- 39:54So you have the AST and you find a place that you want to make a modification and then you make a modification to it.
- 39:59And there's support in the AST module for doing that kind of work.
- 40:02Once you've modified the AST, you then need to get it, you need to make it available to your test suite.
- 40:08You need to make it importable.
- 40:09And that's a whole other kind of second level trick.
- 40:13Yeah, because there's one thing to say, hey, Python, run this module.
- 40:16It's another to load up an individual AST and then turn that into executable things, right?
- 40:22Exactly.
- 40:23Everything it depends upon and so on.
- 40:25That was sort of the second big phase of work in building Cosmic Ray was figuring out how to do that.
- 40:32So once you have an AST, a modified AST, you can pass that to the built-in compile function.
- 40:38And that spits out what's called a code object.
- 40:40And that's this kind of thing that modules can use, so to speak, that we can execute to populate a module.
- 40:46So figuring out how to make that available, make your modified AST available through standard import was a big goal of Cosmic Ray.
- 40:56We didn't want people to have to modify their test suites to do mutation tests.
- 40:59We wanted the test suites to just naturally say import, you know, import of the module and get the right one.
- 41:05So we had to do a lot of investigation into how Python does this.
- 41:09And at the core, there's three main moving parts to how Python does imports, how it lets you control imports.
- 41:17The first thing is what's called a finder.
- 41:20And a finder is an object that's responsible, a class typically, but a function or a class that's responsible for telling Python that it knows how to load a module given that module's name.
- 41:32So Python will ask the finder, I've been asked to import foo.
- 41:36Do you know how to do anything with foo?
- 41:38And a finder can say yes or no.
- 41:39If a finder does know how to load something, it returns what's called a loader.
- 41:45And the loader is then responsible for populating essentially the shell of a module.
- 41:52So Python will make the empty shell of the module, pass it to the loader, and say, okay, now you populate this with the names, the functions, the name bindings, the constants, all that kind of stuff that come from the module that you're supposed to be loading for me.
- 42:05What we do is in Cosmic Ray, we have our own custom finder.
- 42:09And that finder is given the modified AST, and it's told the name of the module.
- 42:15And if it's then asked by Python, do you know how to load that module?
- 42:19It'll say yes.
- 42:19And then it hands back a loader.
- 42:21We have a custom loader, which also has this AST.
- 42:24And the custom loader is able to compile the AST, and then use that compiled AST to populate the shell module.
- 42:36And then that shell module is passed back to Python, and it gets naturally imported so that everybody can use it.
- 42:42I guess the last sort of moving part in this whole system is something called sys.metapath.
- 42:46If you import sys, you'll see it has an attribute called metapath.
- 42:49Metapath is just a list of finders.
- 42:52And when Python wants to import something, and some experts might tell me that I'm a little bit wrong with the details, but this is effectively correct.
- 42:59Python marches down metapath, asking each finder in order, do you know how to load this name?
- 43:04And the first finder that responds is the one that wins.
- 43:08So what we do is we take our custom finder, we populate it with its AST and its name, and we stick it at the front of metapath inside our worker processes.
- 43:16And these worker processes then are able to hijack the import system, in a sense, and put these mutated ASTs directly into place so that nobody has to know they're there, but they get imported naturally by whoever wants to use them.
- 43:27So that's the long and the short, I guess, of how we stick mutated ASTs into Python programs.
- 43:33Yeah, you really had to dig deep down inside the guts of Python.
- 43:37You had to take the red pill, not the blue pill, right?
- 43:40Yeah, there's a lot of pet archaeology and stuff here to get to the bottom of this.
- 43:45But at the end, it's very elegant and powerful.
- 43:46One of the joys of this project was learning all this stuff that I may never apply again, but I feel like I've reached the next level of my Python expertise, in a sense.
- 43:57Yeah, that's really cool.
- 43:58But it's awesome because you don't change your code to make this happen, right?
- 44:02It adapts to what it has to do to basically take over.
- 44:07Exactly.
- 44:08We work, Cosmic Ray works at a deep enough level that neither your test code nor your code under test needs to be modified to use Cosmic Ray.
- 44:19It should work transparently in all ways.
- 44:23Yeah, that was a big goal of the project.
- 44:24You talked about Celery.
- 44:26Celery is really awesome.
- 44:27There's a couple of other really cool projects that you're kind of built upon.
- 44:33One of them was this thing called TinyDB.
- 44:35Yeah, TinyDB.
- 44:38Well, it is what its name says.
- 44:41It's a tiny database.
- 44:42It's a little embedded file-oriented JSON database that you can import into your Python program and use with basically no configuration.
- 44:52So it was exactly what I was looking for when I was looking for a database for Cosmic Ray.
- 44:57We use the database for basically keeping track of the work order I described earlier.
- 45:03The first thing you do in a mutation testing run is figure out what it is you're going to do and write all that down.
- 45:08We write that into the database.
- 45:09And then as the results arrive back via Celery, we stick the results back into this database.
- 45:14So TinyDB is something that's worked out really well for us so far.
- 45:18And it was, as I said, super easy to use, and it's stuck around so far.
- 45:23I have a feeling that it's going to end up being a bottleneck in larger projects.
- 45:26But that's a gut feeling.
- 45:29I don't have any evidence to indicate that.
- 45:31But if it has to be replaced, then we'll start looking at something like SQLite,
- 45:36or maybe we'll give the user the power to specify MongoDB or whatever they want.
- 45:41But TinyDB is really worth looking at, I think, if you don't have really sophisticated needs in a database
- 45:48and you want something that's just file-oriented.
- 45:49It's a really beautiful little program that worked out of the box with really no reading on my part whatsoever.
- 45:54That's lovely.
- 45:55I really like to use SQLite and SQLAlchemy together.
- 46:00And those work really well in sort of an equivalent way.
- 46:03But I'm a huge fan of the document databases.
- 46:06One of the big selling points, what made me stick with TinyDB, is that it literally is a JSON file.
- 46:13I can open it up in Emacs and just look at it.
- 46:16And I don't have to have any extra tools to examine its contents.
- 46:22I think that that JSON nature is what's going to be its downfall.
- 46:26That's what makes me think it's not going to last that long for this project.
- 46:29But that's been a real selling point, is I can run my tests as I'm testing CosmicWrite,
- 46:35which, as you might imagine, is a real challenge, and then see what's in the database really, really easily.
- 46:40And so my cycle time has been pretty high by using TinyDB.
- 46:45Oh, yeah.
- 46:45That's cool.
- 46:45And it's 100% Python, according to GitHub.
- 46:47That sounds right.
- 46:49Yeah.
- 46:49I don't remember any compilation happening when I used it.
- 46:52Yeah.
- 46:52Nice.
- 46:53Yeah, it has 1,000 stars.
- 46:54So it's doing pretty well.
- 46:55I definitely want to check it out.
- 46:56The other one was DocOpt.
- 46:59Yeah.
- 46:59DocOpt is one of my current favorite packages for not just Python, but for lots and lots of languages.
- 47:07DocOpt is a tool for building command line parsers.
- 47:13But unlike things like ArtParse or the other sort of standard tools for doing this, it takes a kind of a backwards approach.
- 47:20You provide it with a string, which is the POSIX standard help output that you would get from any program.
- 47:29You know, saying usage colon program name, blah, blah, option names and all that kind of stuff.
- 47:33And the text information somebody gets when they type, you know, program dash H.
- 47:38You give that string to Cosmic Ray, and from that it generates a parser that can then parse command line arguments.
- 47:44So you never have to think really hard about, you know, building up these parser objects yourself.
- 47:49Everything is done magically, and all you have to do is think about how your pretty help message is going to look.
- 47:54Which you've got to write anyway.
- 47:56Which, yeah, you either have to write or have to get generated by some other tool.
- 48:01This has the neat effect that embedded in your code somewhere is your full help message that is great documentation, not just for your users, but also other programmers looking at your code.
- 48:12It really, it solves a really annoying problem that everybody and every programmer in the world has, which is writing parsers for command line arguments.
- 48:21And it does it in a really slick way.
- 48:23And one of the interesting things is that, I didn't know this until I looked at DocOpt, is that there actually is a POSIX standard for these help messages.
- 48:31So it can rely on an actual existing standard for defining these things, which is really cool.
- 48:36That is cool.
- 48:37Actually, that's the first way that I had heard of that there was a standard was by learning about DocOpt.
- 48:41Like, wait, there's a standard for the help message?
- 48:43Interesting.
- 48:45I highly recommend that anybody who has to write command line tools and who hasn't tried DocOpt, take a look at it.
- 48:50It's really addictive.
- 48:52And you can produce really, really powerful command line parsers.
- 48:55You know, things like you had with Git, you know, sub-command-based tools and stuff.
- 48:59I guess the other interesting thing about DocOpt is that while it was originally written in Python, the canonical implementation is Python.
- 49:06It exists now for something like 30 languages.
- 49:08So if you're a sometime C# developer, sometime Java developer, sometime whatever developer, you can continue using DocOpt in those languages as well.
- 49:17It's a neat project from that point of view, something that you don't see a lot of.
- 49:21Definitely means the idea of it resonated super well, right?
- 49:24Yeah.
- 49:25Yeah, it did.
- 49:27Okay, so we're getting kind of near the end of the show, and I wanted to ask you, you know, you have a company called 60 North, right?
- 49:34That's correct, yes.
- 49:35Yeah.
- 49:35You and Robert Spolscher, is that right?
- 49:38That's right, yes.
- 49:39You guys work together.
- 49:40Yeah, you guys are up in Norway, which is why I ran into you in Oslo.
- 49:43That's right.
- 49:44That's awesome.
- 49:44Although we also seem to run into each other in London.
- 49:46Yeah.
- 49:47Yeah, what do you guys do there?
- 49:48Well, 60 North, we're not terribly pigeonholed, but we do do a lot of Python work.
- 49:53We do consulting, training, some development of our own as well.
- 49:59We've made some courses for Pluralsight.
- 50:03So if you go to Pluralsight and you look for the Python training courses, we have the Python Fundamentals as our first course.
- 50:08And Python Beyond the Basics, which is sort of the next step, intermediate level, is there.
- 50:13And we're working on a third one, which is Advanced Python, I think, is the official name.
- 50:18And that will be out by the end of the year, hopefully.
- 50:20Okay, yeah.
- 50:21You and I, we're both very passionate about online courses.
- 50:24Tell me, what's in your intermediate and your advanced courses?
- 50:27Oh, I'm going to stretch my brain to remember exactly the contents of those courses.
- 50:32But I know the intermediate course, we start getting into things like decorators, class properties, some of the details of classes beyond just functions and methods.
- 50:42Here's how you define a class and add fields to it.
- 50:45Right, yeah.
- 50:46Getting beyond that.
- 50:47A couple of things that are beyond the basics.
- 50:48You'd be surprised at how many things there are that go into the basic course that are really, really basic.
- 50:54I mean, the course is quite long and doesn't really scratch the surface of Python.
- 50:57So anything like, like I mentioned, decorators or...
- 51:02Probably Lambda, Lambda expression type thing.
- 51:04I think Lambda's in there, context managers, implementing a lot of the Dunder magic methods.
- 51:10That kind of stuff is in the intermediate.
- 51:12And then the advanced classes where you start to get into things like what we talked about earlier, finders and loaders.
- 51:17Or you start getting into meta classes.
- 51:20Things that we classify to a degree as things you might do once a year instead of things that you do every day as a professional Python programmer.
- 51:29I mean, finders and loaders, I programmed Python for 20 years and never used it.
- 51:33But it's an interesting and important part of the language.
- 51:35So it needs to be in there somewhere.
- 51:37Yeah, and once you understand it, maybe you don't use it often, but knowing the mechanics helps you understand a lot of things often at that level.
- 51:44Yeah, and you know you have that in your pocket.
- 51:46And so that might be the most elegant solution for some particular problem you face rather than some horrible hack you would have to come up with otherwise.
- 51:53So the advanced stuff is for people who are using Python a lot and need to find the best solutions and really understand the inner workings of the Python runtime.
- 52:03Yeah, cool.
- 52:04So if you guys have a Pluralsight subscription, go over there and type in Python in the search box and you'll find Austin.
- 52:09Yeah.
- 52:10Yeah.
- 52:12Nice.
- 52:13And you also wrote some books, too.
- 52:14We do have some books.
- 52:15Yeah, we have – the books are based largely on the same material as the Pluralsight courses.
- 52:20And the first one is I think 90% done now.
- 52:24It's on LeanPub.
- 52:24It's called The Python Apprentice.
- 52:27The second and third books, The Python Journeyman and The Python Master, are in the works and will be published probably not this year but soon.
- 52:36And since they're on LeanPub, you can get the early version and we'll keep sending you updates as we make updates to the books.
- 52:43But if you prefer books, these are available as, I think, PDFs and Mobi's and EPUBs on the LeanPub site.
- 52:50Nice.
- 52:51And that's self-publishing, right?
- 52:52That is self-publishing, yes.
- 52:54Yeah, very cool.
- 52:55I'm a big fan of self-publishing.
- 52:56So I like to see when people are succeeding at that.
- 52:59That's great.
- 52:59Yeah, so I'll be sure to link to all those things in the show notes as well.
- 53:03Okay.
- 53:04That'd be great.
- 53:05Yeah, absolutely.
- 53:05Very interesting.
- 53:06Definitely cool.
- 53:07Two more questions before I let you go.
- 53:09What's your favorite PyPI package?
- 53:12I saw the other day there's over 80,000 distinct packages out there.
- 53:16That's an insane number.
- 53:17That's probably why people like PyPI.
- 53:18But there's got to be something that you've had exposure to that you want to share, like, oh, you should check this out.
- 53:25Well, this is going to feel like a bit of a cheat, but DocOpt.
- 53:30DocOpt is one that I, once I learned about it, I started using it on almost every project I use.
- 53:37But I know that it's not that well-known, at least not as well-known as I think it should be.
- 53:41So I'll just put a second vote in for DocOpt.
- 53:45For my money, that's the tool I keep going back to in PyPI every time.
- 53:51And it should be more widely known and more widely used because it's awesome.
- 53:55Yeah, that's awesome.
- 53:56I'll go ahead and throw one for Cosmic Ray in there for you because that's pretty awesome and very interesting to check out.
- 54:03Thanks.
- 54:04Thanks.
- 54:04And then you mentioned Emacs earlier, but if you're going to write some Python code, what do you typically open up?
- 54:10Well, the short answer is Emacs.
- 54:11I've been using Emacs for almost as long as I've been using Python, I think.
- 54:16And it's in my fingers to a degree.
- 54:18If I know that I'm working on just a dedicated Python project, then PyCharm is a wonderful IDE.
- 54:25And it's got a lot of powers that Emacs doesn't have when it comes to working with Python.
- 54:30Well, that Emacs doesn't have yet, I should say.
- 54:34But no, it's really great for just pure Python editing.
- 54:36I guess the reason I stick with Emacs is, well, stubbornness to a degree.
- 54:41I just, I'm old and don't want to change.
- 54:43But I'm also very often working on multiple languages at the same time in any given project.
- 54:48You know, everything from JavaScript to Python to, you know, L to whatever happens to be part of that project.
- 54:54And I find that Emacs makes it easier for me to do that.
- 54:57Or at least it has, it's not, it's the best of, it's the best of breed for that kind of work from what I can tell.
- 55:03And honestly, Python as an Emacs IDE is pretty good.
- 55:07You can do all sorts of fancy stuff in there if you want to spend the time to configure it.
- 55:11And if you use a package like, or a canned Emacs configuration like SpaceMax, you'll find that you get pretty sophisticated support for things like completion right out of the box.
- 55:22You know, you get Jedi support and things like that.
- 55:24So it's, I know that I try not to recommend Emacs to new people, to people getting new to Python because that adds a whole level of complexity.
- 55:32But Emacs as a way of life is, it's an interesting place to be.
- 55:35So you could do a lot worse as a programmer.
- 55:38So any final call to actions for all the listeners while you got the mic?
- 55:43Any more calls to action?
- 55:45Are you looking for contributors to your project?
- 55:47Certainly.
- 55:48Sounded like you were.
- 55:48Certainly Cosmic Ray could use some people who are willing to put in some work.
- 55:54We have, of course, the GitHub issues page where I keep track not just of defects, but also of, you know, the higher level issues that need to be done.
- 56:01I mentioned earlier that we have this pressing need for being able to embed exceptions and processing instructions in our code so that Cosmic Ray can not do certain kinds of mutations.
- 56:12And that's a big project that somebody might be able to take on.
- 56:17We have, I guess, the two other big topics I could think of are support for different kinds of modules.
- 56:24Right now, Cosmic Ray can only work against modules that are written in pure Python codes of .py files.
- 56:28But, of course, there are plenty of other exotic kinds of modules out there.
- 56:32So Cosmic Ray needs to either gracefully skip over those other kinds or learn how to process those.
- 56:37And there's no support for that right now.
- 56:38And that's a big limiting factor.
- 56:40And the other is, this is more of a researchy thing, but the integration with coverage testing that I talked about earlier.
- 56:45Being able to take output from, say, coverage.py and use that to determine how we can narrow down the scope of Cosmic Ray mutation testing runs and make it a more practical tool.
- 56:56But, really, it's, you know, go to the issues page on GitHub and look and you'll see the nature of the things that are going on.
- 57:02Yeah, that would be my call to action, I guess, for Cosmic Ray.
- 57:05All right, fantastic.
- 57:06I'll put the link to GitHub repo in the show notes.
- 57:09So, Austin, it's been really fun to talk about this idea of mutation testing.
- 57:14I think it's a really interesting evolution, if you will, of all the testing tools, right?
- 57:23I can see a place when this algorithm gets tuned and, like, the various optimizations you talked about get in there that this could be a big part of day-to-day work.
- 57:32It's cool.
- 57:32Cool.
- 57:33I'm glad you think that.
- 57:34And thanks for having me on the show to talk about it.
- 57:36It's something I really enjoy talking about in public.
- 57:39So, yeah.
- 57:40Yeah, you bet.
- 57:41You bet.
- 57:42Thanks for being on the show.
- 57:43And it was great to see you last week.
- 57:44Take care.
- 57:44It was great seeing you last week.
- 57:45All right.
- 57:46Bye, Mike.
- 57:46This has been another episode of Talk Python To Me.
- 57:50Today's guest was Austin Bingham.
- 57:52And this episode has been sponsored by Hired and SnapCI.
- 57:55Thank you guys for supporting the show.
- 57:57Hired wants to help you find your next big thing.
- 57:59Visit Hired.com slash Talk Python To Me to get five or more offers with salary and equity presented right up front and a special listener signing bonus of $2,000.
- 58:08SnapCI is modern, continuous integration and delivery.
- 58:12Build, test, and deploy your code directly from GitHub.
- 58:14All in your browser with debugging, Docker, and parallels included.
- 58:18Try them for free at Snap.CI slash Talk Python.
- 58:21Are you or a colleague trying to learn Python?
- 58:23Have you tried books and videos that left you bored by just covering topics point by point?
- 58:28Well, check out my online course, Python Jumpstart by Building 10 Apps at talkpython.fm/course to experience a more engaging way to learn Python.
- 58:37You can find the links from this episode at talkpython.fm/episodes slash show slash 63.
- 58:42Be sure to subscribe to the show.
- 58:44Open your favorite podcatcher and search for Python.
- 58:47We should be right at the top.
- 58:48You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on talkpython.fm.
- 58:58Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 59:02You can hear the entire song at talkpython.fm/music.
- 59:06This is your host, Michael Kennedy.
- 59:08Thanks so much for listening.
- 59:10I really appreciate it.
- 59:11Smix, let's get out of here.
- 59:17I'll see you next time.
- 59:34Bye.