Django - Pagination test
When moving a test from a separate class to a class with other tests, it starts showing 4 posts on the second page instead of 3. If range is changed to 12 it shows 2 posts. Please suggest what is the problem.
def test_correct_page_context_guest_client(self):
posts = [Post(text=f'Тестовый текст {i}',
group=self.group0,
author=self.user0) for i in range(
13)]
Post.objects.bulk_create(posts)
pages = (reverse('posts:posts_list'),
reverse('posts:group_list',
kwargs={'slug': f'{self.group0.slug}'}),
reverse('posts:profile',
kwargs={'username': f'{self.user0.username}'}))
for page in pages:
for page_number in range(2):
with self.subTest(page=page):
response = self.guest_client0.get(
page, {'page': page_number+1})
self.assertEqual(len(response.context['page_obj']),
POSTS_COUNT[page_number])
If the test is left in a separate class PaginatorViewsTest(TestCase): then everything works as it should, but this is the task of the reviewer
I added Post created in SetUpClass to SetUp and deleted it before pagination test with self.post.delete() command