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

Test file import versus system module #5716

Conversation

clebergnu
Copy link
Contributor

This fixes a condition on the test loader for avocado-instrumented, in which it can fail to load module from correct path.

More on #5686

The legacy loader system could pass actual class objects instead of
their names.  This is no longer the case with the resolver, so the
class name will always be a string.

Signed-off-by: Cleber Rosa <[email protected]>
Before nrunner, all test conditions (including errors) were
"communicated" by means of specialized class inheriting from
avocado.core.test.Test.

With nrunner, the conditions are communicated using messages, and that
is true for errors.

The "avocado-instrumented" runner already protects against exceptions
while trying to load/import test modules, so this extra handling is
completely unnecessary.

Signed-off-by: Cleber Rosa <[email protected]>
The load_test() function simply won't work without the path for the
Python module to be imported.

Instead of failing cryptically when trying to do
`os.path.basename(test_path)` with test_path being None, let's flag
that situation and report an error early.

Signed-off-by: Cleber Rosa <[email protected]>
If we fail to import the module we want, and find the class we want,
let's raise a clear exception that will be given to users.

Signed-off-by: Cleber Rosa <[email protected]>
The `sys.path.insert()` strategy being used up to this point is
actually ineffective when the same module name exists elsewhere.

With this change, explicit path of the Python file that contains
the test is used to describe what module to load.

Fixes: avocado-framework#5686
Signed-off-by: Cleber Rosa <[email protected]>
@clebergnu clebergnu added the bug label Jul 10, 2023
@clebergnu clebergnu self-assigned this Jul 10, 2023
@richtja richtja self-requested a review July 11, 2023 14:17
Copy link
Contributor

@richtja richtja left a comment

Choose a reason for hiding this comment

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

Hi @clebergnu, thank you for this loader clean up, it LGTM.

@richtja richtja merged commit d57d4ae into avocado-framework:master Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants