Good morning! Welcome back, Roberts Greibers here, and in this post, I want to talk about my three unit tests tips that have allowed me to get into writing unit tests in Python Django way faster, in a way more scalable way. 

These are unit tests tips that you will definitely need! 

Because when it comes to building a Python Django project you can’t build anything without having proper test coverage. 

If you like the idea of becoming a Python Django developer, building your own Django projects, writing professional code which is also covered with unit tests – this post is exactly for YOU!

These are tips that I literally use every day when I’m working on new features in Python Django and I wish I knew about them when I was just a beginner Python developer. 

I’ve been working professionally as a Python developer for more than 5 years now – and for the past couple of years, I’ve been working in the fintech industry, building a white label payment gateway product for a local company (ourspell.com) in Riga, Latvia. 

You can read more about my experience on my Linkedin here.

I’m also helping junior developers who are at beginning of their careers (see the LIVE mentoring call here) to take a shortcut and basically use my code examples, techniques I have collected over the years and apply them to their own projects to get their first Python Django job opportunities. 

In the end, what I’m about to give you here in this post is just a small portion of what I share with my clients.

But this will definitely help you write better Python scripts if you’re serious about becoming a Python/Django developer. 

How to write unit tests

So the first and foremost unit tests tip that has helped me especially in the beginning stages is that you have to realize it’s POSSIBLE to get to a point where it’s very easy for you to write professional Python code.

And the key to this process is actually writing very well-planned unit tests, especially when you’re working on Django projects – you have to write unit tests, there’s no other way to build a scalable Python Django project! 

And it’s funny because I just recently talked about this with one of my clients and she asked me the following questions.

  • How do you even know the answers to all the exceptions and error situations we get?
  • How do you know what to test in each unit test?
  • How do you write code that doesn’t break?
  • Why can’t I use the actual data in unit tests? (For context: in unit tests you should be using mock data)

And the key point we both realized is that it all came down to her old mindset. 

She never thought we’re not supposed to check the real data in tests. (more about that later in the post.. check our conversation in LIVE call video recording below)

Why you need to forget your old way of thinking

You have to realize the following.. Your old way of thinking is not going to get you anywhere, that’s your real problem!

Even if you’ve been listening to what people tell you to do, the usual stuff:

…even with all of the above – you are where you are in life because of the way you think. 

You can’t write proper Python code because you’re stuck in your old ways. 

Things changed for me, ONLY when I learned: “Hey, you don’t need to stay the way you are – if you put more effort into making your coding decisions, you can probably do better! You can write better code!”

Especially when I just started to do my first Python projects, University homework, etc. I always was under the presumption that there are two kinds of people:

  • Those who have it who are meant to become Python developers
  • And then there are people who don’t have that, who are meant to be average, be normal and just work as a manual testers (QA engineers)

And that’s me, right – that’s what I used to think. 

At Riga Technical University graduation day
At Riga Technical University graduation day

And I knew a lot of people from my university class, I knew they are the ones who are going to be successful. 

I always thought they are meant to become Python developers, but me – not so much. 

Maybe it was because I came from a smaller town to the capital city of Latvia – Riga to go to University and study alongside the smartest students in the country. 

I always thought every single one of them are smarter than me, they were like math geniuses with 90% exam results and I was just a regular guy, I’m not gonna even mention my math exam results, haha – definitely not 90%. 

The truth about unit tests

But I somehow just thought like, for me, the average life is meant to be. 

Only somewhere in the middle of already being a QA engineer for a while, working with Python projects here and there, I realized the following:

Hold on a second, you can actually learn to write higher quality code that doesn’t break.

I learned – It’s not all random!

You can learn to become a better Python developer who can become confident in the Python code he writes. 

And essentially it all comes down to writing unit tests in Python Django.

Because that’s the only way to check your own code – that’s the only way you can validate your own thinking. 

And you’d be surprised how many times I thought: “Well, this should work properly”, but then I wrote a couple of unit tests to validate specific situations and realized I have to completely change a part of the code to make it work. 

This might sound completely normal to you. 

But for me, writing unit tests in Python Django was really the most important realization I came to.

It was the spark that ignited the fire in me, knowing that there is a way out – and I can actually become really good at writing Python code, building Django projects. 

Your mindset when writing unit tests

This is something that has grown within me as a mindset over the last couple of years.

Every time I have an idea of building a project that is so big, so grandiose, or I have a task to build a feature that I think is so difficult to finish. 

I tell myself the following…

  • “Hold on a second, you thought that before!”
  • “You thought of that just as much when you were a total beginner, writing simple if statements, for loops”
  • “You thought of that when you built your first Python projects”
  • “So whatever that task is now, it’s also totally possible to do it with proper execution and as long as you keep writing unit tests in your Django project, you’ll be fine.”

And that is always the set of rules I’m operating under, EVERYTHING IS POSSIBLE if you put in the work and properly handle all the possible situations with unit tests. 

Of course, you have to work hard, you have to be willing to take a lot of professional sacrifices, as it can be a bit difficult to start to write unit tests for each part of the feature you develop if you’ve never written unit tests in Django before. 

But if you actually want to become a professional Python developer, you have to be willing to work and cut a lot of spare time out of your life to get to a decent level. 

But ultimately, that’s all you need. 

It’s possible to become a real Python Django developer even if the chance is slim.

But also — You will need help. Yes, you should ask for help. 

Why you should ask for help

Now, let’s talk about the second point – it’s okay to ask for help!

I feel like especially when it comes to becoming a Python Django developer, a lot of beginner developers out there saying “I want to be self-made, I want to do everything myself, I don’t need help”. 

But ultimately, even if someone is, “self-made”, they still have people that they learn from. 

And this is very, very KEY – listen…

It’s totally fine to ask for help!

I mean, it’s foolish not to do so if you really think about it!

How you should ask for help

Like the lessons that I’m teaching to my mentoring clients – it would literally take them years to figure out these lessons by themselves. 

When besides having unit tests you need help from a mentor (Python Django)
When besides having unit tests you need help from a mentor (Python Django)

…And that’s foolish! Why would you do that? 

Why would you deliberately voluntarily waste years of your life? 

If you can just ask someone:  “Hey, how did you do it? Can you tell me what I got to do next? Is this good?”

Debugging step-by-step together with a mentor (Python Django)
Debugging step-by-step together with a mentor (Python Django)

And you just literally progress always doing the RIGHT thing! Instead of having to do trial and error. 

There is, of course, still trial and error involved when you have someone that helps you.

But at least you’ll be guided through it…

And you just literally make progress – always taking the RIGHT steps, whether it’s writing proper unit tests or choosing the correct techniques, new principles. 

You’ll be guided in terms of interpreting the mistakes you’ve done.

And really helping you to find the correct solution –  the right way it’s done in Python Django.

What’s actually holding you back

Get away from your ego horse, get off that ego horse of thinking you got to be a self-made Python Django developer.

Don’t think it’s a sign of weakness to ask for help!

In fact – it’s a sign of being smart!

When you’ll get hired as a Python Django developer all you’ll be doing is asking questions and asking for help – that’s the way you usually work with your dev team!

It’s a sign of being mature enough to put your results above everything, including your ego!

Even if you’re already in IT, you need THIS

I love the fact that whenever I have a client who may even be relatively advanced, familiar with Python, already working in IT for a couple of years, even older than me, living in the US, pretty much already have a good life, but still interested to learn and switch to a Python development position.

So you know, they have an IT job already, they’re the king in their own world. 

And I love it when we have a call – I give them a little bit of a hard time – I point out mistakes that they need to fix. 

And even though they’re already pretty good at their current IT positions they’re able to just swallow the pride and say – “Okay, cool – I’ll fix it. – Thanks for the feedback. Oh, thanks for pointing out the mistakes I’ve made.”

This is rarer than you think – lots of people have issues with taking feedback. 

And then they can’t implement the Python Django feature I tell them to build for their projects. 

That’s literally some sort of success barrier – it takes way more time for them to become a developer. 

Results over everything

This brings us to the third tip here, and its results over everything. 

This doesn’t make you a Python developer

Nowadays, there are so many free Python tutorials out there. Also, books about Python that you can read.

Python tutorial videos on Youtube you can watch, and so on and so forth. 

Most of them are just “feel good” content – nothing about the tools and techniques you actually need to be able to build Python projects on your own. 

Or even worse, teaching people the tools and ways of doing things that would never be used in a real Python Django project.

Stop watching Python tutorials that get you nowhere
Stop watching Python tutorials that get you nowhere

And maybe this post has even started a little bit “feel good”. 

“It’s possible” – but in reality who cares if you feel really confident becoming a Python developer?

RESULTS OVER EVERYTHING!

You’re not a Python developer if…

If you cannot build a feature and write code for your own Python portfolio projects – you’re not a Python developer.

If you can’t even build a Python Django project for yourself, how are you going to do it for a tech company?

But maybe you know a lot about Python and you’ve been to this and that Python training, university, etc. 

If you’re not able to build Python Django projects on your own, it does not count!

It’s mind-blowing – you don’t even know –  I’m going to tell you one secret!

My Linkedin inbox is full of this

How many messages do I get on Linkedin saying: 

  • “Yeah, Roberts, you know, I have this and that experience”.
  • “I have a computer science degree blah, blah, blah, can you help me become a Python Django developer?”

And I say: “Good. Well, have you built any Python projects yet?”

They’re like: “Oh, well, I’m haven’t done anything yet” 

Me:

“Well, if you don’t even have a Python project yet, you’re not a developer.”

“If you’re barely familiar with Python fundamentals I still might be able to help you, but it’s gonna require hard work from you.”

“Okay, how many people out there think you’re already a developer?”

The mind-blowing answer:

“I’m already a developer because I write on my Linkedin profile: Python developer”

The truth about being a Python developer

SPOILER ALERT: Having a Linkedin profile doesn’t make you a Python developer! 

Creating a LinkedIn profile with a Macbook from your big brother or from your friend doesn’t make you a Python developer.

Being able to build stable Python projects makes you a Python developer. 

Having good reviews from your former employers about the projects you built for them makes you a Python developer. 

Alright – Results over everything!

That’s the only thing that ever counts in the real world.

Conclusion

And these, my dear reader, are the three unit tests tips that have helped me greatly. 

So when you’re reading this post and you also want to become a Python Django developer, start your career as a Python developer by writing proper software, unbreakable code tested with Python unit tests…

…then let’s schedule a free consulting call with me personally, there’s information somewhere down below to do that.

All you need to do is follow the steps, contact me, and will probably jump on a free call to discuss your situation, I’ll see if there’s anything I can do to help you become a Python Django developer. 

And on that call, I’ll be looking at your situation I’ll be analyzing your current coding skill level, I can tell you what exact model would fit for you and your specific situation, what steps you need to take in order to get started, and get your first Python job opportunities. 

Even if you already feel you know Python and you want to learn more – this call is for you!

If you feel a little lost, you have no idea what you could be learning to become a Python Django developer, this call is for you as well! 

I can help you out with a lot of clarity!

And even if you already know what it is that you should be learning, but you’re struggling on your own – that call is for you as well!

So like I said, the information to contact me is down below, I want to thank you very much for reading, I really appreciate you, and let’s talk soon!

I'll help you become a Python developer!

If you're interested in learning Python and getting a job as a Python developer, send me an email to roberts.greibers@gmail.com and I'll see if I can help you.

Roberts Greibers

Roberts Greibers

I help engineers to become backend Python/Django developers so they can increase their income