when i am running the test its storing the inner functional data to main db 
not test db why ?

On Monday, January 9, 2023 at 2:32:20 PM UTC+5:30 sencer...@gmail.com wrote:

> Hi,
>
> I try to get coverage reports using a simple django model.
> Unit test for model was written but report says there are missing 
> statements.
>
> *The model:*
>
> from django.db import models
> from model_utils import FieldTracker
>
> from generics.base_model import BaseModelMixin
>
> class AModel(BaseModelMixin):
>     record_name = models.CharField(max_length=255)
>     tracker = FieldTracker()
>
>     class Meta(BaseModelMixin.Meta):
>         db_table = 'a_model_records'
>
>     def __str__(self):
>         record_name = self.record_name
>         if record_name is None:
>             record_name = "N/A"
>         return record_name
>
>
> *The unit test:*
>
> class TestAModel(TestCase):
>
>     def setUp(self):
>         super().setUp()
>
>     def test_allowed_domain_model(self):
>         record_name = "some name"
>         is_active = True
>
>         user = User.objects.first()
>         record = AModel.objects.create(
>
>             record_name=record_name,
>             is_active=is_active,
>             created_by_id=user.id,
>         )
>
> self.assertEqual(str(record), record_name)
> self.assertEqual(record.name, record_name)
> self.assertEqual(record.is_active, is_active)
>
>
> *The command line code I run:*
>
> source activate
> set -a
> source local.env
> set +a
> coverage run --source="unit_test_app" --rcfile=.coveragerc 
> project/manage.py test -v 2
> coverage report
> coverage html
>
> *The coverage configuration is like this:*
>
> [run]
> omit=
>     */migrations/*
>     */tests/*
>     */manage.py
>     */apps.py
>     */settings.py
>     */urls.py
>     */filters.py
>     */serializers.py
>     */generics/*
>
> [report]
> show_missing = true
>
>
> *Coverage result shows 1 missing:*
>
> [image: image.png]
>
> This is the simplest example.
> There are many ignored functions by coverage which descends percentage 
> average, but actually covered by unit tests.
> Why does coverage act like this?
>
> Kind regards,
> Sencer HAMARAT
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/89acdec2-b889-47a8-b146-8179db80d8a4n%40googlegroups.com.

Reply via email to