oracle / oracle/oci-python-sdk

Fixture order not guaranteed (pytest < 3.5.0)

Open
#196 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
474
Forks
321
Avg merge
23m
Merged PRs (30d)
4

Description

I realize there's a min pytest version specified in requirements but it seems to be incorrect. The tests seem to run fine at anything matching pytest >= 3.5.0. In 3.5.0 the order of fixture instantiation based on scope was added and this breaks the tests for anything older. However, there is an easy fix which I think is worthwhile and could allow the min pytest version to be lowered even further. Below is the patch diff of the changes that would be required:

Index: oci-python-sdk-2.6.2/tests/unit/test_basic_api_calls.py
===================================================================
--- oci-python-sdk-2.6.2.orig/tests/unit/test_basic_api_calls.py
+++ oci-python-sdk-2.6.2/tests/unit/test_basic_api_calls.py
@@ -5,7 +5,7 @@ import oci
 import pytest
 
 
-def test_identity_list_users(identity, config):
+def test_identity_list_users(config, identity):
     response = identity.list_users(config["tenancy"])
 
     assert response is not None
@@ -31,7 +31,7 @@ def test_vcn_list_instances(compute, con
     assert response.request_id is not None
 
 
-def test_limit(identity, config):
+def test_limit(config, identity):
     response = identity.list_users(config["tenancy"], limit=1)
 
     assert response is not None
Index: oci-python-sdk-2.6.2/tests/unit/test_waiters.py
===================================================================
--- oci-python-sdk-2.6.2.orig/tests/unit/test_waiters.py
+++ oci-python-sdk-2.6.2/tests/unit/test_waiters.py
@@ -108,7 +108,7 @@ def test_wait_multiple_states(virtual_ne
     assert total_time < 60 * 5
 
 
-def test_invalid_operation(identity, config):
+def test_invalid_operation(config, identity):
     # Create User
     request = oci.identity.models.CreateUserDetails()
     request.compartment_id = config["tenancy"]
@@ -131,7 +131,7 @@ def test_invalid_operation(identity, con
         oci.wait_until(identity, response, 'not a real property', 'test')
 
 
-def test_already_in_state(identity, config):
+def test_already_in_state(config, identity):
     description = 'test user'
     request = oci.identity.models.CreateUserDetails()
     request.compartment_id = config["tenancy"]
@@ -151,7 +151,7 @@ def test_already_in_state(identity, conf
     identity.delete_user(user_id)
 
 
-def test_wait_time_exceeded(identity, config):
+def test_wait_time_exceeded(config, identity):
     description = 'test user'
     request = oci.identity.models.CreateUserDetails()
     request.compartment_id = config["tenancy"]
@@ -182,7 +182,7 @@ def test_property_and_eval_function_prov
     assert str(ve.value) == 'If an evaluate_response function is provided, then the property argument cannot also be provided'
 
 
-def test_eval_function_lambda(identity, config):
+def test_eval_function_lambda(config, identity):
     user_id = None
     try:
         description = 'test user'
@@ -206,7 +206,7 @@ def test_eval_function_lambda(identity,
             identity.delete_user(user_id)
 
 
-def test_eval_function_func_ref(identity, config):
+def test_eval_function_func_ref(config, identity):
     user_id = None
     try:
         description = 'test user'

The fix is just changing the order of fixture imports to ensure the config fixture is always prior to identity. The config fixture skips the test if there's no config file available instead of failing the test.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/unit/test_basic_api_calls.py and tests/unit/test_waiters.py, reviewing the fixture argument order shown in the issue. Run the tests with pytest older than 3.5.0, where fixture ordering is not guaranteed. Done means the affected tests consistently skip cleanly without a config file and pass when configuration is available.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.