---
slug: "django-unittest-expected-actual"
title: "The \"first\" and \"second\" Arguments of assertEqual in Django's Unit Tests are Actually \"expected\" and \"actual\""
description: "When looking at the assertEqual method in Django's unit tests, the first argument is named 'first' and the second argument is named 'second'. It appears that there is no difference in the usage of these variables."
url: "https://www.ytyng.com/en/blog/django-unittest-expected-actual"
publish_date: "2024-03-28T00:41:49Z"
created: "2024-03-28T00:41:49Z"
updated: "2026-02-26T07:19:52.063Z"
categories: ["Django", "Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250611/f538129f31c34a84a4676b587317fb54.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/304/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/304/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/304/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/304/featured-music-304-3.mp3", "https://media.ytyng.net/ytyng-blog/304/featured-music-304-4.mp3"]
lang: "en"
---

# The "first" and "second" Arguments of assertEqual in Django's Unit Tests are Actually "expected" and "actual"

When we look at the `assertEqual` method in Django's unit tests:

```python
def assertEqual(self, first, second, msg=None):
    """Fail if the two objects are unequal as determined by the '=='
       operator.
    """
    assertion_func = self._getAssertEqualityFunc(first, second)
    assertion_func(first, second, msg=msg)
```

The first argument is named `first` and the second argument is named `second`, and it seems like there is no difference in their usage.

However, if you write code like the following:

```python
from django.test import TestCase

class AssertTest(TestCase):
    def test_assert_equal(self):
        self.assertEqual(
            'expected',
            'actual'
        )
```

When the test actually fails, the result will output:

```
Failure
Expected :'expected'
Actual   :'actual'
```

Therefore, you should consider the first argument to be Expected and the second argument to be Actual.

For this reason, the hardcoded value in the unit test is Expected, so it should be the first argument. The result of the method execution or the variable holding the result is Actual, so it should be the second argument.

```python
self.assertEqual(
    110,
    get_tax_included_price(100)
)
```

Nevertheless, if you look at actual examples of Django's unit tests, you will notice that the order can be reversed. So, in practice, either order is acceptable.

Ideally, a tool like [Black](https://github.com/psf/black) would decide on one to standardize.
