diff mbox series

[7/8] Toaster: fixed: Tests fail when executed one after the other out of sequence

Message ID 20231030195037.232912-7-alassane.yattara@savoirfairelinux.com
State New
Headers show
Series [1/8] Toaster: Update toaster-requirements.txt to add pytest and some plugin's | expand

Commit Message

Alassane Yattara Oct. 30, 2023, 7:50 p.m. UTC
As mentionned in earlier commit, pytest-django takes a conservative approach
to enabling database access. By default our tests will fail if they try to access
the database, Only if we explicitly request database access will this be allowed,
using pytest marks to tell pytest-django our test needs database access.

A side effect of pytest mark, is test_case method marked is execute out of
scope of its module class, which create an inconsistance sequence and make fails
followings tests.

The scope of the ordering is global per default, e.g. tests with lower ordinal
numbers are always executed before tests with higher numbers in the same test session,
regardless of the module and class they reside in. This can be changed by using
the --order-scope option from module pytest-order.

To fix that i added execution order to tests suite using pytest-order.

Signed-off-by: Alassane Yattara <alassane.yattara@savoirfairelinux.com>
---
 lib/toaster/tests/functional/test_functional_basic.py | 4 +++-
 lib/toaster/tests/toaster-tests-requirements.txt      | 1 +
 lib/toaster/tests/views/test_views.py                 | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

Comments

Tim Orling Oct. 31, 2023, 3:07 p.m. UTC | #1
On Mon, Oct 30, 2023 at 12:51 PM Alassane Yattara <
alassane.yattara@savoirfairelinux.com> wrote:

> As mentionned in earlier commit, pytest-django takes a conservative
> approach
> to enabling database access. By default our tests will fail if they try to
> access
> the database, Only if we explicitly request database access will this be
> allowed,
> using pytest marks to tell pytest-django our test needs database access.
>
> A side effect of pytest mark, is test_case method marked is execute out of
> scope of its module class, which create an inconsistance sequence and make
> fails
> followings tests.
>
> The scope of the ordering is global per default, e.g. tests with lower
> ordinal
> numbers are always executed before tests with higher numbers in the same
> test session,
> regardless of the module and class they reside in. This can be changed by
> using
> the --order-scope option from module pytest-order.
>
> To fix that i added execution order to tests suite using pytest-order.
>
>
This seems like a reasonable explanation of what is happening and why the
change is being made.


> Signed-off-by: Alassane Yattara <alassane.yattara@savoirfairelinux.com>
>
Reviewed-by: Tim Orling <tim.orling@konsulko.com>

> ---
>  lib/toaster/tests/functional/test_functional_basic.py | 4 +++-
>  lib/toaster/tests/toaster-tests-requirements.txt      | 1 +
>  lib/toaster/tests/views/test_views.py                 | 2 ++
>  3 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/lib/toaster/tests/functional/test_functional_basic.py
> b/lib/toaster/tests/functional/test_functional_basic.py
> index 7e9be91c..f558cce8 100644
> --- a/lib/toaster/tests/functional/test_functional_basic.py
> +++ b/lib/toaster/tests/functional/test_functional_basic.py
> @@ -8,12 +8,14 @@
>  #
>
>  import re, time
> -import pytest
>  from django.urls import reverse
> +import pytest
>  from tests.functional.functional_helpers import SeleniumFunctionalTestCase
>  from orm.models import Project
>  from selenium.webdriver.common.by import By
>
> +
> +@pytest.mark.order("last")
>  class FuntionalTestBasic(SeleniumFunctionalTestCase):
>
>  #   testcase (1514)
> diff --git a/lib/toaster/tests/toaster-tests-requirements.txt
> b/lib/toaster/tests/toaster-tests-requirements.txt
> index 7109c625..71cc0834 100644
> --- a/lib/toaster/tests/toaster-tests-requirements.txt
> +++ b/lib/toaster/tests/toaster-tests-requirements.txt
> @@ -4,3 +4,4 @@ pytest-django==4.5.2
>  pytest-env==1.1.0
>  pytest-html==4.0.2
>  pytest-metadata==3.0.0
> +pytest-order==1.1.0
> diff --git a/lib/toaster/tests/views/test_views.py
> b/lib/toaster/tests/views/test_views.py
> index 06bf6c20..349881eb 100644
> --- a/lib/toaster/tests/views/test_views.py
> +++ b/lib/toaster/tests/views/test_views.py
> @@ -9,6 +9,7 @@
>
>  """Test cases for Toaster GUI and ReST."""
>
> +import pytest
>  from django.test import TestCase
>  from django.test.client import RequestFactory
>  from django.urls import reverse
> @@ -33,6 +34,7 @@ PROJECT_NAME2 = "test project 2"
>  CLI_BUILDS_PROJECT_NAME = 'Command line builds'
>
>
> +@pytest.mark.order(1)
>  class ViewTests(TestCase):
>      """Tests to verify view APIs."""
>
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#15331):
> https://lists.openembedded.org/g/bitbake-devel/message/15331
> Mute This Topic: https://lists.openembedded.org/mt/102283465/924729
> Group Owner: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [
> ticotimo@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
diff mbox series

Patch

diff --git a/lib/toaster/tests/functional/test_functional_basic.py b/lib/toaster/tests/functional/test_functional_basic.py
index 7e9be91c..f558cce8 100644
--- a/lib/toaster/tests/functional/test_functional_basic.py
+++ b/lib/toaster/tests/functional/test_functional_basic.py
@@ -8,12 +8,14 @@ 
 #
 
 import re, time
-import pytest
 from django.urls import reverse
+import pytest
 from tests.functional.functional_helpers import SeleniumFunctionalTestCase
 from orm.models import Project
 from selenium.webdriver.common.by import By
 
+
+@pytest.mark.order("last")
 class FuntionalTestBasic(SeleniumFunctionalTestCase):
 
 #   testcase (1514)
diff --git a/lib/toaster/tests/toaster-tests-requirements.txt b/lib/toaster/tests/toaster-tests-requirements.txt
index 7109c625..71cc0834 100644
--- a/lib/toaster/tests/toaster-tests-requirements.txt
+++ b/lib/toaster/tests/toaster-tests-requirements.txt
@@ -4,3 +4,4 @@  pytest-django==4.5.2
 pytest-env==1.1.0
 pytest-html==4.0.2
 pytest-metadata==3.0.0
+pytest-order==1.1.0
diff --git a/lib/toaster/tests/views/test_views.py b/lib/toaster/tests/views/test_views.py
index 06bf6c20..349881eb 100644
--- a/lib/toaster/tests/views/test_views.py
+++ b/lib/toaster/tests/views/test_views.py
@@ -9,6 +9,7 @@ 
 
 """Test cases for Toaster GUI and ReST."""
 
+import pytest
 from django.test import TestCase
 from django.test.client import RequestFactory
 from django.urls import reverse
@@ -33,6 +34,7 @@  PROJECT_NAME2 = "test project 2"
 CLI_BUILDS_PROJECT_NAME = 'Command line builds'
 
 
+@pytest.mark.order(1)
 class ViewTests(TestCase):
     """Tests to verify view APIs."""