As great as version control and unit testing are for keeping your overall code organised and functional, neither actually help you rightwrite cleaner code.
- Version control will allow you to see how and when the code got as messy as it is.
- Unit tests will make sure that, despite the code being a complete mess, it still works.
If you want to stop yourself from writing messy code, you need a tool that works where the messes happen: when you're writing the code. A popular kind of tool that does is called a linter. I'm not a python developer, but it looks like Pylint might be a good option.
A linter looks at the code you've written, and compares it to a configurable set of best practices. If the linter has a rule that variables must be camelCase, and you write one in snake_case, it will flag that as a mistake. Good linters have rules ranging from "declared variables must be used" to "The cyclomatic complexity of functions must be less than 3".
Most code editors can be configured to run a linter every time you save, or just generally as you type, and indicate problems inline. If you type something like x = 7, the x will be highlighted, with an instruction to use a longer, better name (if that's what you have configured). This works like spellcheck in most word processors, making it hard to ignore, and helping to build better habits.