Using mock objects during testing in Python.

Transcript for episode 132 of the Test & Code Podcast

This transcript starts as an auto generated transcript.
PRs welcome if you want to help fix any errors.

00:00:00 Today we are talking about mocking and using mock objects during testing in Python. Analyt Popkis joins the podcast to teach us about mocks. We discuss the different styles of using mocks, pros and cons of mocks, the Adapter Pattern, Mock, Health, Magical Universe, and so much more. This portion of Test and Code is sponsored by Talk Python Training. Do you want to get better at Python? Now is an excellent time to take an online course, whether you’re just learning Python or you need to go deep into things like APIs and async our friends at Talk Python Training have a top notch course for you. Stick around until the end of the show to hear how you can win a free course. Visit Talk Python dot FM test to find your next level that’s talkpython. Fmtest.

00:00:58 Welcome to Testing Code.

00:01:10 Welcome to Test and Code. Am super excited to have on today’s show, Annalina Popkas and I first ran across her name. It was a couple of years ago. She was doing this really cool thing with teaching people how to actually she was learning how to code also, but 100 days of code type thing, but with like a fantasy thing, magical universe. We’ll talk about that a little bit. But today she’s here to talk with us about MOX. So before we get into all that, can you tell us a little bit about who you are?

00:01:40 Yeah, sure. I’m really excited to be here today. So I’m currently working as a machine learning engineer in a German company called Innovax. But I’m usually working on machine learning problems and my background is also in machine learning. But the past couple of months I’ve been working only in data engineering, so I’ve been learning a lot more about the work that comes before applying the actual machine learning algorithms. But yeah, that’s what I do day to day. And in my free time, I’m spending a lot of time with voluntary project I’m working on. It’s German. So it’s called Kaema Church. Like AI goes school or AI goes to school, where we teach AI and machine learning skills to kids in German schools, which is also a lot of fun. So yeah, I’m really into machine learning.

00:02:27 Okay. And machine learning, AI and data science, these are all related things, but you’re treating them as you’re talking about them as if they’re all different.

00:02:35 Well, yeah, I think it’s a bit difficult since there is no clear convention with the naming. Different people define it slightly different, but yeah, for me, data science is much broader than machine learning. And then we have deep learning, which is for me also just a specific type or a field in machine learning. But I guess you can discuss about the meaning of the different terms for a while.

00:03:03 Yeah. Okay. Let’s talk about Magical Universe a little bit before we jump into the rest because it’s such a cool project.

00:03:09 Yeah, I really like it too.

00:03:10 Tell me how you started doing this and tell me a little bit about it.

00:03:14 Yeah. I think for the first time, I heard about this 100 Days of Code challenge on either Python Bytes or Talk Python. To me, it’s like three years ago, and then I started working on it myself. So I thought about a project or I wanted to look into some of the more advanced Python features a bit. And I needed something to make it fun for myself, since it’s usually hard to sit down after work to do something that’s also like studying.

00:03:44 And I’m a big Harry Potter fan. So I decided to create my own magical universe with spell classes and students and ghosts and potion making and so on and use that as an inspiration for looking at the different Python features. And yeah, I will also be giving a keynote talk at PyCon, Estonia in October. And it’s called Finding the Magic in Python. So that’s also inspired by this magical universe project.

00:04:15 Oh, that’s cool. And so this is something people can find and follow along with this, right?

00:04:21 Yes. So it’s both on GitHub and on my personal webpage, which is Alpcas. So my last name, then and there in my blog posts, you can find the different days and what I worked on. But also on my GitHub page, there is the code for each day and like the entire code at the backstory.

00:04:45 Nice. Yeah. We’ll definitely put links in the show notes, and I encourage people to check it out. The last question I had about this was the 100 Days of Code challenge. It’s a neat idea, and there are some pre canned challenges where people come it’s not fixed, though. People can come up with their own challenges and whatever they’re doing during the 100 days. Did you come up with all of this on your own, or did you modify it from somebody else’s challenges?

00:05:10 No, I actually came up with it on my own. I was reading a Python book a few months before that. It was Dan Bader, and then it was Python Tricks, something. I don’t remember the full name right now, but he was talking about some of the features of Python I did not know before, like abstract base classes. Iterators I think, also. So I decided I really want to learn a bit more about these things. And it’s always hard to just read about a concept and then fully understand it. You usually have to write some code, and that’s why I was looking for some kind of topic I could code about.

00:05:49 Well, I think it’s really cool, and we’ll link to it. Like I said, of course, it’s pretty neat. I love Dan Bader’s work, too. He’s really great for the community.

00:05:58 I’m also planning on extending the universe, since there are a few more concepts that I want to look into more. And I’m also thinking a bit more about the characters in my story at the moment for the Python for the keynote talk. So I guess I will be extending the project in the future.

00:06:14 Oh yeah, I think that’s wonderful. Have you had very much feedback from people?

00:06:18 So in the very beginning I created a post on Reddit and there I got a ton of positive feedback and people really liked it. Maybe that’s because so many people are looking for something that is not the classical example for abstract based classes, but really to have a single story that you can use to go through all of these features. I think that was something novel that people haven’t seen before. And yeah, that’s at least I think that’s neat.

00:06:54 Let’s face it, your code is going to have errors, even code written by a kickass developer such as yourself. And when bad things happen, it’s nice to know Honey Badger has your back. Honey Badger makes you a DevOps hero by combining error monitoring, uptime monitoring and Cron monitoring into a single easy to use platform, all for way less than you’re probably paying now. Honey Badger monitors and sends error alerts in real time with all the context needed to see what’s causing the error and where it’s hiding in your code so you can quickly fix it and get on with your day. The included uptime and Crown monitoring also lets you know when your external services are having issues or your background jobs go AWOL or silently fail. Go to Honeybadger. Io and discover how Star, Josh and Ben created a 100% bootstrap monitoring solution. Why is this important? Self funding means they only answer to you, the developer and not a venture capital. Overlord test and code listeners get 30% off for six months. Simply mention the Test and Code podcast when signing up and they’ll apply the discount to your account. No credit card required.

00:07:57 Are you cool with jumping into mocking now?

00:08:00 Yes, let’s do that.

00:08:02 Okay, I’m really excited. A lot of people have asked me about mocking, so let’s jump into it. So if somebody doesn’t know what mocking is, what is mocking?

00:08:09 So marking can be used if you want to test code and you want to isolate certain parts of your code. So a mock simulates the existence and the behavior of a real object, and that can allow you to write better tests or test code in a controlled environment, then maybe if you have code with external dependencies, you can mock out those such that you can test your code without actually calling or writing to database every time. And there are different use cases, I guess. And for me it was also a completely new topic. I only used it for the first time when I started working with Data Engineering project where we work in the Google Cloud and there you interact with the cloud so many times. Like every day when I write code, I usually interact with a cloud in some way. And you don’t want to write to the cloud storage every time you run your tests and other stuff. So there it can be really handy.

00:09:10 Okay. When you say interacting with the cloud, what does that mean? Does that mean like making calls to a particular API or something?

00:09:18 Yeah. For example. So one thing that we do regularly. So in the Google Cloud, you have service that’s called storage and it’s just object storage where you can put all your files or objects into Socalled buckets. And all our processes either write files to these buckets or look at which files are already in there and then work with them and download them or do some other stuff. And you usually have to create a client, Google something client, and then you can use that client to list the files in a bucket or upload a file to a bucket or download a file from a bucket and so on.

00:09:58 Okay, so I’ve never used this before.

00:10:00 I’m creating a client object. I guess there’s some API call to create a client object and then the exactly. I use that to get access to more information that way through it.

00:10:12 Yes.

00:10:12 So is that client object? Is that the point where you’re using mocks in your tests?

00:10:16 Yeah, that’s one point where we use it. But we also have use cases where we have like OS remove or we interact with the request library, like standard use cases which are not related to Google Cloud, but things where you actually don’t want to call an object during your tests.

00:10:39 Okay, the obvious question I’ve got, maybe it’s not obvious. I want to test to make sure my software works. If I’m mocking or pretending making a fake one and I’m not interacting with part of it, isn’t that cheating?

00:10:56 It’s not going to work because it’s not real.

00:10:58 Well, it depends. So let’s say you have a function and you have some logic in your function, but somewhere in the middle it writes or in the end the file is written to a database and you want to test the function and you want to make sure that when you create a mock object, then you can make sure in the end you can assert that the mock object has been called with certain arguments and maybe you want to make sure that the rest of your code works. And then in the end the call to the storage service is called with the correct arguments. That’s something you could assert on a mock. I think that’s also why I like mocking so much. It’s also this magical thing, right. You create your mock object and it behaves, it can do anything for you. You just tell it like you have this attribute now or I want to call this function with these inputs and it will just all create those things on the fly. And I find that very fascinating.

00:11:53 So, yes, the system that you’re testing uses an external system. But the part of the code that you’re trying to test within these particular tests isn’t really reliant on the external system too much getting that right.

00:12:07 Yeah. So I guess it depends a bit. So first thing is, of course, if you use Mocking or Patching, then the thing you’re patching, it’s replaced by a mock. So that object that has nothing to do with the original implementation of the class or the method that you are replacing with a mock. So that’s something you have to keep in mind. So in the end, at some point, maybe you can do an integration test where you then really check that the API is called correctly, but that’s nothing you want to do 30 times a day when you can make changes to your code base.

00:12:42 Like the example you gave where the output is just stored into the cloud that you’re testing the rest of all the algorithm. And when the file comes out, you can either replace it with a memory file or something. Not at all.

00:12:55 Yeah. That’s also something that we only recently discovered, since Mocking can be great and it can help a lot, but it can also become very difficult and complex to use if you have too many external dependencies. And I was actually listening to one of your podcast episodes on that with Harry.

00:13:19 Yeah. And I watched his Python talk and stopped using mocks for a while. I think it’s called. And so that’s also a problem we stumbled across. When you start using mocks, it can be really helpful and can make testing so much easier. And then maybe you can test functions that beforehand were really difficult to test, but it can also become difficult. So maybe you can get to a point where you have to rethink your architecture and maybe there are a few different or better ways to design your code.

00:13:52 Yeah. So I do encourage people to, if they’re listening to this, also watch Harry’s Talk and listen to the episode with Harry Percival on too, because it’s a good discussion. But also Mocking is very powerful as well. And useful.

00:14:06 Yeah, I agree.

00:14:07 So let’s see, we haven’t set it out directly, but you’re using unit test mock when we’re talking about Mocking.

00:14:14 Yes. That’s what we use, like almost all the time.

00:14:18 Okay. And there’s a couple of flavors of the mocks in there. There’s normal mocks and magic marks. Are you using a little bit of both?

00:14:26 So, yeah, there’s mock, Magic Rock and Patch. So those are the core functionalities. And when I create an object, I usually use mock, since Magic Mock is just a subclass of mock and it implements some of the magic methods for you. So they are pre created and ready to use, like Thunder Length or Stir and so on. And usually if you don’t need those, then you can use a mock object. However, if you patch. So if you use the patch function and you have your call to the patch function and you replace a call to a certain method or a class, then that instance or the class or method gets replaced with a magic mock by default. So in this sense, I also use magic marks since I use patching and I usually don’t replace this default value of the magic Mark.

00:15:18 And you know, one of the things that I get wrong is when I think of magic Mark. Actually, it’s the magic methods. It’s not like the dungeon methods and stuff. When I mentally for some reason I’m switching it. I’m thinking about auto spec. Do you know what auto spec does?

00:15:32 Yes.

00:15:33 Okay, I’ll probably get this wrong, but my understanding is that parameter you pass in and I don’t know if it’s part of magic mock or just or mock or both of them, I don’t know. But if I say I’m going to mock this other object, it copies all of the basically creates mocked methods for all of the methods of the object I’m creating. Is that right?

00:15:55 Yes. So there are different kinds of spec. There’s just spec, there’s auto spec and specs. I think that’s it. And the thing is that when you create mocks, they will create objects on the fly. I think I mentioned that already, and that has also that can cause problems since the mock object does not know the interface of your class or method. So it does not know which attributes it can be called with. And you can basically put any inputs into a function if you call it if that’s mocked. And in some cases you want to make sure that your mock has an actual idea of what it should look like. And then you can use the spec or spec set or auto spec, and then you can only call the mock objects with the or you can only call the methods on the mock object that are actually defined in the class. And that can be quite helpful. However, there’s also one thing that I find really annoying is namely if you have instance attributes like you have a class that you want to mock or patch and you use the spec or auto spec attribute and you cannot then use the attributes that are defined in the constructor like in the Dunder init method, since I think it’s due to the internal workings of auto spec that it cannot know about these things. Okay, yeah. So spec then only knows about visible attributes. So it can also be annoying if you don’t know that before.

00:17:22 Right in the Dunder method isn’t being called. So it’s not going to set all of those things. But yes, I imagine you can. Hopefully I don’t know if you can combine the two and do an auto spec and then set other attributes you need afterwards, but maybe it won’t let you don’t know.

00:17:40 I actually think you cannot do that. Then afterwards if you use spec, you can only call those attributes and methods on the object that are defined in the class, so you can set it like as class attributes, maybe, and then you can use them. But after you use spec on one of the others, then your mock object is configured. At least that’s what I have in my head right now. I think that’s the case.

00:18:05 Yeah. Makes sense to me. Sure. If anybody knows otherwise, they can get a hold of us, correct? Yes, that’s good.

00:18:15 High Charm is the Python IDE for professional developers. High Charm’s huge collection of tools out of the box includes an integrated debugger and test runner, Python profiler, a built in terminal, integration with version control and built in database tools, remote development capabilities with remote interpreters and integrated SSH terminal, and integration with Docker and Vagrant. In addition to Python, PyCharm provides first class support for various Python web development frameworks, specific template languages, JavaScript, Coffee script TypeScript, HTML, CSS, AngularJS NodeJS and more. High Term, integrates with IPython notebook and has interactive Python console and supports Anaconda, as well as multiple scientific packages including Map, Lib and NumPy. Try out all of these timesaving features of PyCharm for four months with the link. Testingcode PyCharm make sure your editor is working with you to save you time. Use PyCharm the idea of replacing a part of your system with a mocked object because, for instance, you don’t want to talk to an external cloud service or something like that, totally makes sense. There’s other ways, other types of testing where you’re trying to make sure something happens, like you create a mock object, but then you call your other code and then do a search on to make sure that a certain function was called with certain parameters and stuff like that. So sometimes you care about how the mock object was being used in the test, and sometimes you don’t. So how are you using it in your machine learning work?

00:19:50 So I’ve never used mocking and machine learning before. Like I said, I only used mocking, or heard of mocking for the first time in the state of engineering project. That might be the case because there is not much testing and machine learning, which is not a good thing, and I think that’s a big problem on its own, that there’s far too little testing. I know it’s difficult to test a machine learning model.

00:20:13 Okay.

00:20:15 Okay. The data engineering side.

00:20:17 Yeah.

00:20:18 Are you usually using them just to replace part of the system that you don’t want to be called, or are you inspecting them afterwards, whether or not they’re doing anything?

00:20:26 We’re doing both. So one use case we have a lot is that we, for example, want to upload the file to the cloud storage, and you want to make sure that the function has been called with the correct arguments. That’s something you can assert with. Sometimes you can just we only care about that a function has been called. So there is then the assert mock, dot assert called once or assert called with. But I think most of the time we don’t use it just to replace code, but make sure that the mock has been called correctly.

00:21:03 Okay, nice. There’s a lot of documentation out there about the different names for mocks and stuff, but in your work, you and your colleagues, do you talk about like spies and test doubles and stuff, or do you just really talk about mock objects?

00:21:17 We usually talk about mock objects. I’m not sure whether the others know about dummies, fakes and stuff. I never mentioned them since I think they can be quite confusing. And for our use case, we use mocking most of the time, so we don’t use spies. Or maybe we use dummies, but no one really cares about how it’s called what we do. So no, I never discuss the different types of test doubles with them.

00:21:46 Okay. And it might be different in other languages and I don’t know how to do it in other languages, but that confused me a little bit when I started reading about mocking came across these articles of like mocks are not stubborn, stubborn, that thing. And I’m like, well, what am I doing something wrong? And well within pytest, not pytest, but within Python most of the time we’re using the unit test mock library. And so I think it confuses people to try to separate all these things because we use the same library for all of them.

00:22:24 Yeah, I agree. So there’s also a lot of disagreement about this terminology and there’s also not a clear cut definition for most of the term. So it’s all a bit blurry and some people define it like this and others like that. I think there is some agreement about the difference between a stop and a mock or mock and a spy, but it can be unnecessarily complicated to distinguish these different types. So I think if you just start and start to learn about mocking, then don’t get confused by these different terms.

00:22:58 So we hinted at it a little bit that there are some downsides. So there’s definitely some benefits to be able to use mocks and tests. So what are some of the things to be careful about?

00:23:08 Yeah. So there is actually a very nice also Python talk on mocking and patching Pitfalls, which is talking about mockhill and the different stages of mockhill. And we stumbled into mockhill quite a few times too. So using mocking can become quite complex. There are things like that you have to configure your mock and doing that becomes very complicated or it can be difficult to understand how to patch a function.

00:23:38 It’s very easy to break marks since especially if you have your external dependencies and you don’t have this additional lay of abstraction between them. These adapters that Harry was talking about, then you can easily break your tests by just changing import statements or. Yeah. So there are a lot of things you have to be careful about, and there are a few very easy ways out, like dependency injection. So what that is, is that let’s say you have the cloud storage and you have a client to interact with cloud storage. And in the beginning, what we were doing is that in a function or in the class, you define one of these clients and then you use the client to, I don’t know, upload a file. And what you can do instead is that you pass an instance of the client to the class when you create an instance of it, or you pass an instance of the client to method. And that makes it so much easier. Since then, when you have your test, you don’t need to patch that client, but you can just call the function with a mock object. And these little things can make life so much easier already.

00:24:53 Yeah. And dependency injection is something that we don’t really some people are using it heavily in Python, but it is not as common in Python as other places, but there are places where we use it that I think people might not realize that they’re using dependency injection. So some web frameworks, for instance, will do a thing where they’ll set up in your main application file, they’ll set up the database client and the other services set up, and then those are set in the application little application file, and then you don’t care about them anymore. But behind the scenes, what’s happening is defining the object to handle the database interaction and setting it in place. Now it’s not passed through like a lot of dependency injections is passing it through all the function calls everywhere. We don’t have to do that in Python, but the similar sort of model of defining in one place, those are actually pretty cool systems if you can do that, because you can do stuff like replace the database with an in memory database during testing and then run with it. So I wouldn’t recommend people do dependency injection on all of the dependencies on all functions. That would be crazy. But some of the main external dependencies, I think it’s a cool idea and it can help.

00:26:07 Yeah, I agree. And it’s a very simple change. It’s not like the adapter pattern where you have a lot of overhead in the beginning since you have to rethink how you design your code. But it’s a very easy thing to change.

00:26:21 Yeah, definitely. And is that what Harry called his solution is an adapter pattern? Do you remember?

00:26:28 I’m not sure whether he called it adapter pattern, but okay, there was adapter somewhere in there.

00:26:35 Yeah. And the idea of people don’t want to listen to that. I think if I’m going to get it right, is having an interface layer that you control that talks to the external whatever external dependency you have allows you complete control of the API, so you can mock your own stuff easily or replace it with something fake or something like that.

00:26:56 Yeah, I think that was a perfectly accurate description.

00:26:59 Plus, Harry’s been thinking about this for a long time. Smarter.

00:27:03 I found it very interesting, too, since that’s a design pattern I had heard of before. So you have your external dependencies, and in the beginning you think about what are they? And then you have this wrapper or this adapter class that you can create, and it somewhat defines this desired interface. But what I like is that you have to minimize the width of the interface. So with the Google Cloud storage, for example, we most of the time don’t need all the functionality it offers, but we just maybe need to list files in a bucket and upload files to a bucket. So instead of directly interacting with the Google Cloud, you can create your own little class that has just these two methods, list files in bucket and maybe upload file to bucket, and then have this additional layer of abstraction. And that has a lot of advantages.

00:27:56 Yeah. And one other advantage that you’ve got there is when you were working with those with that system and you think you need another dependency, you need to call something else in the cloud. You have to kind of step back and think, am I doing something really more unique than was being done before? Why do I need this extra interface that nobody else needed before me?

00:28:17 Yeah, it’s a completely different way to approach this problem, and I like learning about it, especially since, as I said, you have to really rethink how you create your code and you somewhat minimize the ways in which you can interact with service like the Google Cloud. And it makes it so much easier if you want to switch providers. Like if you in the end want to use AWS and not the Google Cloud anymore and you don’t have to rewrite all your code and all your tests, but you can just create another instance of this adapter class that is specific to AWS.

00:28:55 Yeah. And I’ve heard an argument before that this being flexible to be able to replace something isn’t real because people don’t usually switch databases or something like that. And that might be true for some things. But I don’t know if cloud storage is something that people would replace. I do know of at least one person I know that had to switch data storage providers because of cost. But the example that Harry gave in his talk is, I think a credit card processor, which totally makes sense how you might have to switch that. And it also makes sense that the API would be completely different between the two. But in your system, how you’re charging the client is such a minor part of your system that having to depend on one cloud provider would be annoying. So it’s a good example, I think.

00:29:44 Yeah, definitely. I agree.

00:29:46 Okay. Did I completely off track us tangents?

00:29:50 No, I don’t think so.

00:29:52 Any other downfalls or tricky things that people need to watch out for?

00:29:56 I think in the beginning you have to learn about how you use the patch function. So there is this difference between you have the place where you define the object and the place where you use the object.

00:30:07 And I think it’s very useful to take a look at these mocking and patching pitfalls talk. Since then, you are a bit more sensitive to noticing when you get into problems with mocking and when you just start mocking everything and are looking for an easy way out rather than refactoring your code and doing it properly.

00:30:32 Yeah. So I encourage people the important part, it’s hard to describe if you haven’t run into it, but if you’re playing with examples of mocking writing a little test function that mocks something else, it’s probably going to be easy because it’s right all in one file. So what you want to do is go through some examples of swapping out some part of some function within your own test code or within the test file and then do it where you’re replacing some part of an imported module and then do it where you’re trying to replace something deep down inside that’s imported by the thing that you’re importing that the test code doesn’t even I mean, that’s the hard part when you’re trying to replace something like really in the middle of something that gets called like three levels down or something like that.

00:31:20 I agree. Yeah, that’s a good idea.

00:31:22 And Detroit, but still do it with like a toy example, because when you’re trying to do it with like live code, it’s too stressful.

00:31:30 Yes, I agree.

00:31:32 But you said it well in your discussion with Michael Kennedy, which hasn’t been out yet. But you also talked with Michael Kennedy for Talk Python on some of this. And I do believe people should listen to both because they’re good conversations. But one of the things you brought up was that once you learn it, it’s easy.

00:31:50 The import problem, once you get your head around it, then you have your head around it and you’re like, oh, okay, you have to mock and patch where the item is used and how it’s used, not how you think about it. And the example you gave. Let’s just talk about that a little bit. Again, if a module says import request as RQ, I don’t know why people would do that. Then you have to patch RQ. You can’t patch requests. Right.

00:32:19 So I agree. I think at least for me, it was the case that once I went through enough examples to really understand the difference between where something is defined versus where it’s used, then at some point you see the idea and then it becomes so much easier. But in the beginning, I guess you have to go through a few examples and actually do it yourself. That’s what you just said. Come up with your own examples and don’t always use the easy thing to patch, but try to create something a bit more complicated.

00:32:53 Yeah. And also can’t remember who I heard this from. It may have been you that one of the benefits of doing this, working with monkey patching and mocking and stuff is you get an understanding of how Python namespaces work because that’s what you’re doing. You’re changing an element in the namespace. And yeah, that’s a really good lightning bold moment when people finally get how namespaces kind of work, or at least they have a working mental model of how namespaces work in Python.

00:33:23 Yeah, I’m not sure if I agree.

00:33:24 Yeah, I’m not sure if I still actually know how they work, but I have a working mental model that’s the same for me.

00:33:30 I’m not sure whether I could explain how they work, but at least I know what to expect when I use them.

00:33:37 Yes.

00:33:38 Anyway, we’ve covered a whole bunch of stuff. Did we miss something that we need to talk about?

00:33:43 No, I don’t think so.

00:33:45 You had this point on whether I learned about testing at University?

00:33:50 Oh, yeah, because I’m just assuming since that you were at University more recently than I was.

00:33:56 Yes.

00:33:57 So did you. I can’t remember. What was your field of study? Was it computer science?

00:34:02 No, actually not. So I studied cognitive science in my undergraduate degree, so I had nothing to do with coding, and I never expected to end up as a computer science, but I did. So I started studying cognitive science and I wanted to work in neuroscience. And I actually spent a semester abroad at Harvard Medical School where I worked on dyslexic children, or the group did FMI research on children with dyslexia. So I really did neuroscience, where you look at voxels of fMRI scans and try to analyze them. And I only stumbled across machine learning at the very end of my undergraduate degree and I had no idea about coding. I never used Python before, but I found it really interesting, this idea that you can have algorithms that learn from data.

00:34:56 And then I looked for computer science graduate degree that I would be allowed to do without having any programming experience and without having an undergraduate degree and a degree that would allow me to focus on machine learning and not necessarily have to learn all the other things that exist in computer science. So that was also when I first started to use Python. Okay, so maybe back to your question with the testing. So since I did not study computer science and, well, not general like normal computer science, I never heard of testing and I did not learn anything about it, not even in the machine learning classes. But I guess that’s something that, as I said, a general problem in machine learning that so many people don’t test their codes and especially in research, it’s just nothing that they are focused on.

00:35:55 They have their Jupiter notebook, they write some hacky code. And if you like software engineering and design principles behind it, you look at the code and you think it’s awful. It looks just so Hecky and bad. And I remember that when I started my AI residency at Microsoft and we got talking and I asked like, but how do you know that it works? And they have, of course, the mathematical proofs behind it and so on, but they never actually for it. I was like, how does that work? So it’s really a completely different world, I guess, but it’s getting better also that you upload your code with the paper when you publish a machine learning. That’s also something that not many people are doing at the moment, which is crazy.

00:36:43 Well, hopefully it will become more so I would really like to see if there’s any coding at all in a program. They should talk about the testing part. The question that you said, the key question is how do you know that it works?

00:36:56 Yes.

00:36:58 I’m baffled. I know that people that learn electronics learn how to use Oscopes when they’re in College. So why do we not teach testing?

00:37:07 It might be different in the US, and it might be different in German undergraduate degrees in computer science, but I learned most that’s true. Like, most of the knowledge I have about testing is from the beginning of my residency, like, in the first project, I had an amazing engineering supervisor, and his name is Jordan. And he was so specific about giving us the time to learn about testing and to test all our code properly. And whenever we had meetings with the full researchers and him as our engineering supervisor, he was the researchers were always pushing for doing more research and going on with the project. And he was always like, take your time, do the tests properly, take a look at it and learn about the different kinds of testing that you have unit testing and integration testing and regression test. And that really helped me so much with the other work I’m doing at the moment.

00:38:03 Wonderful. Well, let’s see, before we get off of this, I hope that there’s a University Professor or a handful of them that are really mad at me right now because the things have changed and we do teach testing now. Yes, I hope so. Please get a hold of me and we’ll come on and we can talk about how testing is being taught at universities now when it wasn’t in the 90s, I would love to hear from people and for people that want to hear you again, you were talking at what was the conference you’re going to be talking about it’s Python, Estonia. Okay. And is that going to be do I have to travel to Estonia or.

00:38:37 No, they do it in a remote fashion. So they have still a live conference with live talks. But it’s all like the people can stay home and listen to the talks from home.

00:38:50 Okay. And do you happen to know when that’s going to be held?

00:38:53 Yes, it’s in October. It’s on a Thursday. It’s the 8 October.

00:39:00 Okay, cool.

00:39:01 Let me double check.

00:39:04 Yes, well, we will drop a link into the show notes for PyCon Estonia also. Yes, I’m depressed that I didn’t have Python us live, but I am thrilled that the places that are these conferences from all over the world are online because I would have never been able to go see Pike, Calastonia talk in the past. Yeah, it’s very cool.

00:39:25 I agree. Also for Python us, you have all the talks online now and there are so many great things and also the tutorials, it’s amazing that it’s possible to do that now.

00:39:35 Yeah, very wonderful. There’s definitely downsides to what’s going on in the world right now, but also benefits.

00:39:41 Yeah.

00:39:41 Well, thank you so much for your time and for all this great information and I wish you the best of luck in all your future endeavors.

00:39:48 Thank you. Thank you so much for having me.

00:39:53 Thank you, Annelina. That was a great discussion. I really appreciate your time. Thank you, Patreon supporters for continuing to support the show. Join them by going to support. Thank you Pie Charm for sponsoring the show. Try pycharm at PyCharm. Thank you Honey Badger for sponsoring check them out at Honeybadger. Io mention test and code and get 30% off. Thank you talkpythontraining for sponsoring check it out at talk. Python. Fmtest to level up your skills, enter to win a free course by joining this show’s mailing list at Subscribe all those links as well as a ton of links that we talked about in the show one, three, two. That’s all for now. Now go out and test something.