Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 6068:Make the test class dependencies fulfill all the tests. #6079

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wangp-h
Copy link
Contributor

@wangp-h wangp-h commented Dec 5, 2024

Cause of the Issue:
The cause of the issue is that the 'type' field is removed from the dependencies_dict (using pop('type')), which causes the 'type' field to no longer exist in the dictionary during subsequent operations. When trying to assign the value of 'type' to the kind attribute through the Dependency.from_dictionary method, the dictionary no longer contains the 'type' field, which results in kind being incorrectly set to None.

Solution:
By using deepcopy(dependencies_dict), a copy of dependencies_dict is created, so any changes made to the copy (new_dependencies_dict) do not affect the original dictionary. This ensures that the 'type' field remains intact in the copied dictionary, allowing the correct assignment of kind from the 'type' field when calling Dependency.from_dictionary(d), thus avoiding the issue caused by modifying the original dictionary.

@wangp-h
Copy link
Contributor Author

wangp-h commented Dec 5, 2024

Steps to test

class PassTest(Test):
    """
    Example test that passes.

    :avocado: dependency={"type": "package", "name": "git"}
    """

    def test(self):
        """
        A test simply doesn't have to fail in order to pass
        """
    
    def test_1(self):
        """
        A test simply doesn't have to fail in order to pass
        """

The current behavior is as expected

$ avocado run examples/tests/passtest_with_dependency.py
JOB ID     : bc0cd13e74d5639e34032caba6d5336ad2ac8f6d
JOB LOG    : /root/avocado/job-results/job-2024-12-05T19.41-bc0cd13/job.log
 (2/2) examples/tests/passtest_with_dependency.py:PassTest.test_1: STARTED
 (1/2) examples/tests/passtest_with_dependency.py:PassTest.test: STARTED
 (2/2) examples/tests/passtest_with_dependency.py:PassTest.test_1: PASS (0.01 s)
 (1/2) examples/tests/passtest_with_dependency.py:PassTest.test: PASS (0.02 s)
RESULTS    : PASS 2 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME   : 2.14 s

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.87%. Comparing base (b80f298) to head (fd83b15).
Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #6079       +/-   ##
===========================================
+ Coverage   54.32%   68.87%   +14.55%     
===========================================
  Files         202      202               
  Lines       21892    21894        +2     
===========================================
+ Hits        11892    15079     +3187     
+ Misses      10000     6815     -3185     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@clebergnu clebergnu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wangp-h,

Thank you so much for investigating and fixing this issue. Given your findings, I've found that an easier fix is possible:

diff --git a/avocado/core/dependencies/dependency.py b/avocado/core/dependencies/dependency.py
index 2f77c5763..46473d6e3 100644
--- a/avocado/core/dependencies/dependency.py
+++ b/avocado/core/dependencies/dependency.py
@@ -58,7 +58,7 @@ class Dependency:
     @classmethod
     def from_dictionary(cls, dictionary):
         return cls(
-            dictionary.pop("type", None),
+            dictionary.get("type", None),
             dictionary.pop("uri", None),
             dictionary.pop("args", ()),
             dictionary,

This reduces the amount of data that is copied, and I was not able to find any negative side-effects. Let me know what you think about this alternative.

@wangp-h
Copy link
Contributor Author

wangp-h commented Dec 12, 2024

Hi @wangp-h,

Thank you so much for investigating and fixing this issue. Given your findings, I've found that an easier fix is possible:

diff --git a/avocado/core/dependencies/dependency.py b/avocado/core/dependencies/dependency.py
index 2f77c5763..46473d6e3 100644
--- a/avocado/core/dependencies/dependency.py
+++ b/avocado/core/dependencies/dependency.py
@@ -58,7 +58,7 @@ class Dependency:
     @classmethod
     def from_dictionary(cls, dictionary):
         return cls(
-            dictionary.pop("type", None),
+            dictionary.get("type", None),
             dictionary.pop("uri", None),
             dictionary.pop("args", ()),
             dictionary,

This reduces the amount of data that is copied, and I was not able to find any negative side-effects. Let me know what you think about this alternative.

Hi, @clebergnu, thank you for your comments and suggestions! Yes, your modification could solve the issue, but it would affect the values of the dictionary in the original logic. Although I haven't done further debugging, this might cause some other issues. Therefore, I believe my change is more appropriate.

@clebergnu
Copy link
Contributor

Hi, @clebergnu, thank you for your comments and suggestions! Yes, your modification could solve the issue, but it would affect the values of the dictionary in the original logic. Although I haven't done further debugging, this might cause some other issues. Therefore, I believe my change is more appropriate.

Hi @wangp-h,

I did a good deal of investigation, and I'm quite sure that the dictionary is used only for the purpose of the requirements, so there's no harm in modifying it. It's really better than adding an extra copy given that the original won't be used for anything else.

Also, the exact version of your changes has import style issues.

And finally, there's a problem unrelated to this fix, but that get's hit only when a fix is applied. You can see some failures in the requirements.py tests. Some escaping is needed for one of the tests that generate a JSON file. The fix is as simple as:

diff --git a/selftests/functional/serial/requirements.py b/selftests/functional/serial/requirements.py
index 6f6dbfb4e..f275f3263 100644
--- a/selftests/functional/serial/requirements.py
+++ b/selftests/functional/serial/requirements.py
@@ -131,11 +131,11 @@ DEPENDENCY_FILE = """
 """
 
 DEPENDENCY_RECIPE_FMT = """
-{
+{{
   "kind": "avocado-instrumented",
   "uri": "{path}",
-  "kwargs": {"dependencies": [{"type": "package", "name": "hello"}]}
-}
+  "kwargs": {{"dependencies": [{{"type": "package", "name": "hello"}}]}}
+}}
 """

We should integrate that fix into the same PR, or in a previous PR, so that CI is happy at the merge time.

Signed-off-by: wangpeng <wangpengb@uniontech.com>
@wangp-h
Copy link
Contributor Author

wangp-h commented Dec 19, 2024

Hi, @clebergnu, thank you for your comments and suggestions! Yes, your modification could solve the issue, but it would affect the values of the dictionary in the original logic. Although I haven't done further debugging, this might cause some other issues. Therefore, I believe my change is more appropriate.

Hi @wangp-h,

I did a good deal of investigation, and I'm quite sure that the dictionary is used only for the purpose of the requirements, so there's no harm in modifying it. It's really better than adding an extra copy given that the original won't be used for anything else.

Also, the exact version of your changes has import style issues.

And finally, there's a problem unrelated to this fix, but that get's hit only when a fix is applied. You can see some failures in the requirements.py tests. Some escaping is needed for one of the tests that generate a JSON file. The fix is as simple as:

diff --git a/selftests/functional/serial/requirements.py b/selftests/functional/serial/requirements.py
index 6f6dbfb4e..f275f3263 100644
--- a/selftests/functional/serial/requirements.py
+++ b/selftests/functional/serial/requirements.py
@@ -131,11 +131,11 @@ DEPENDENCY_FILE = """
 """
 
 DEPENDENCY_RECIPE_FMT = """
-{
+{{
   "kind": "avocado-instrumented",
   "uri": "{path}",
-  "kwargs": {"dependencies": [{"type": "package", "name": "hello"}]}
-}
+  "kwargs": {{"dependencies": [{{"type": "package", "name": "hello"}}]}}
+}}
 """

We should integrate that fix into the same PR, or in a previous PR, so that CI is happy at the merge time.

Hello, @clebergnu, thank you for your investigation and for reviewing the code again. I've resubmitted the PR based on your review comments. Please help review it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review Requested
Development

Successfully merging this pull request may close these issues.

2 participants