• Complain

Adam Johnson - Speed Up Your Django Tests

Here you can read online Adam Johnson - Speed Up Your Django Tests full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2021, publisher: Adam Johnson, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

No cover
  • Book:
    Speed Up Your Django Tests
  • Author:
  • Publisher:
    Adam Johnson
  • Genre:
  • Year:
    2021
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Speed Up Your Django Tests: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Speed Up Your Django Tests" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

This book is a practical guide to making your Django projects tests faster. It has many tips and tricks that apply to all projects, big and small. And it covers the two most popular test runners: Djangos test framework and pytest.Its based on my experience speeding up various Django projects test suites, improving Djangos own testing framework, and creating pytest plugins.

Adam Johnson: author's other books


Who wrote Speed Up Your Django Tests? Find out the surname, the name of the author of the book and a list of all author's works by series.

Speed Up Your Django Tests — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Speed Up Your Django Tests" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Table of Contents
Introduction
The measure of success most often is speedDoing things better is synonymous - photo 1

The measure of success most often is speed.Doing things better is synonymous with doing things faster so that we can do even more things efficiently and effectively.In buying into this premise, we enter a spiral of acceleration that we can never hope to master.

Diana Scharf Hunt and Pam Hait

Welcome, dear reader.

Oh, tests.

Tests are great.Tests show us where bugs are at least some of them.Tests help us to not add new bugs.

But tests.Tests are also a frequent source of frustration.When you first started writing tests, you probably found them an extra nuisance to write.You probably still think the same, at least sometimes.

Even if you love writing tests, running them can be boring.Slow tests can make you lose concentration, juggle tasks, and end up getting less stuff done.They can suck all the fun out of programming.And programming is meant to be fun!

Theres a phase shift when you speed up your tests, restoring that joy.If your tests take 1000 seconds and you reduce them to 600 seconds, youll feel it.Your whole team will feel it.The same happens if you can reduce a test run from 30 seconds down to 10 seconds.

And theres no limit to fast enough.Reducing test run time is the easiest and safest way to increase your speed of delivery.And your organization wants to deliver as fast as possible, to get valuable features and fixes in front of users.

Fast tests also tend to be more accurate tests.Theyre well targeted, so they only fail when a feature is broken.And with less overhead, you can exercise features more completely.

The content is based on my eight years of experience with tests on Django projects.Ive sped up many projects test suites, improved Djangos own testing framework, and created several pytest plugins.

In your hands, or at least on your screen, is my best guide for speeding up tests on your project.Ive tried to cover most situations, so you should be able to find something relevant to your project.

May it reduce your test speed and your test pain.Enjoy!

Adam

P.S. Please send me any and all feedback through the contact details on my site.

Who Is This Book For?

If you are a Django developer working with tests, this is for you.No matter your level.

My aim is to make the book readable by a junior developer who has been given the vague task of improving the tests, but also to include material that even long time Django users may not have come across.Ive tried to be opinionated enough to be actionable, but provide advice thats applicable to all projects.

A Brief Tour of This Book

The first two chapters, , explain the various tools you have at hand for modifying and measuring your tests respectively.

The next six chapters cover ways of speeding up your tests without the bother of rewriting your test code (much). cover ways of speeding up your tests in configuration for those environments.

The three chapters that follow cover how to write fast tests. shows some focussed techniques for replacing components during testing that can help you write better, faster tests.

Finally, the gives some closing remarks and links to further reading.

In a rush?

To get the 80% of improvements that take 20% of the effort:

  • Record your current test runtime with a shell timing command as in .

  • Skim to understand the pieces youre changing.

  • If you dont yet run your tests in parallel, read .

  • Learn how to reuse your database and squash your migrations in .

  • Do as many of the upgrades described in as possible.

  • Compare your test runtime!

If after this, your tests are still too slow, profile them with one of the tools described in the second half of .Then when you know where to focus, read the later chapters to determine ways of speeding up the slowest tests.

Examples

This book has a lot of code examples.I hope that is not a surprise!

Heres some information on their layout.

Commands

Commands to run in your shell look like this:

$ python --version

The $ represents the prompt - dont type that.Im using macOS but hope to have removed any macOS or *nix bias.Commands should work cross-platform, but where thats not possible Ive added a separate Windows example with a PowerShell prompt:

> python --version

If Ive written something incompatible with your platform (most likely Windows), please let me know.

Versions

Examples have been prepared with Python 3.9 and Django 3.2.Im only using the official Python distribution, CPython, since Django or its dependencies often dont work on other Python interpreters.

Python code is formatted with Black.(Like Django itself will be one day.)Import statements are sorted and grouped with isort.And all code is also linted with Flake8.

Throughout, I refer to installation commands with:

$ python -m pip install Django

Im using python -m pip as per pip developers recommendations - see my blog post on the subject.

Please read these commands as install using your dependency management solution.There are several tools for this in the Python ecosystem, and I cant cover them all.

If you arent using any dependency management tool (beyond pip), pip-compile is a great start as its a small layer on top of pip.Its also my preference.

Django Projects

The example projects Ive used are based on my simple-core startproject template.This has directory structure like this:

$ tree . example __init__.py core __init__.py models.py tests __init__.py test_models.py settings.py urls.py manage.py 3 directories, 8 files

This is slightly different to Djangos normal startproject template.The whole project lives inside a single Python package, example . example.core is an app, inside which there are models and tests.This is counter to the Django default of having apps in modules that are peers to the project app.

I prefer this layout because it makes it clear when youre importing something belonging to your project.Owned names always start with example (or whatever your project is called).

resources.zip

This PDF also came with a resources.zip .This includes all the example projects.Theyre structured with one directory per chapter, within which there are several individual projects.

When a file would be particularly useful to open, I mention the file name to open.Otherwise, the code examples dont refer to their file names, since they should stand alone.If you do find yourself wanting to refer to some code, the files should be named well enough to figure out which one you want.

Snipped Output

Quite often in examples, I snip the code or output to keep it short and discard irrelevant details.You can spot this whenever theres a ... .For example, here Ive snipped the list of subcommands:

$ python manage.py --helpType 'manage.py help ' for help on a specific subcommand.Available subcommands: [ django ] check ... testserver

In Python, ... is also syntactically valid - its the rarely needed Ellipsis object .This never has any meaning in my examples.

Acknowledgements

Thank you to everyone who helped me put this book together.

Thanks to my partner Mafalda for her love, encouraging me to carry on when I needed it, and encouraging me to stop at the end of the day.Thanks to my parents - my mum for sharing her experience as an author, and my dad for proofreading this book with the same care he applied to every homework essay and CV.And thanks to my brother and sister-in-law for their support.

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Speed Up Your Django Tests»

Look at similar books to Speed Up Your Django Tests. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Speed Up Your Django Tests»

Discussion, reviews of the book Speed Up Your Django Tests and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.