[PATCH 2/4] test: Drop u_boot_ prefix on test files
Simon Glass
sjg at chromium.org
Sat Jan 25 23:41:43 CET 2025
Hi Tom,
On Sat, 25 Jan 2025 at 14:46, Tom Rini <trini at konsulko.com> wrote:
>
> On Sat, Jan 25, 2025 at 02:31:37PM -0700, Simon Glass wrote:
>
> > We know this is U-Boot so the prefix serves no purpose other than to
> > make things longer and harder to read. Drop it and rename the files.
> >
> > Signed-off-by: Simon Glass <sjg at chromium.org>
>
> This is a massive bit of churn and violating namespace best practices
> when it seems like we really need:
> [snip]
> > diff --git a/test/py/tests/fit_util.py b/test/py/tests/fit_util.py
> > index 16ff8c96c63..7aad4030be3 100644
> > --- a/test/py/tests/fit_util.py
> > +++ b/test/py/tests/fit_util.py
> > @@ -5,7 +5,7 @@
> >
> > import os
> >
> > -import u_boot_utils as util
> > +import utils as util
The real namespace is the one in site-packages, where you are supposed
to put things in their own modules. The Python tools operate in a
proper namespace, but so far the tests don't. They just use whatever
directory the file is in. So, for example, we have:
from tests import fs_helper
where 'tests' is the subdir in test/py
One option would be to move the pytests up a directory, with test.py
in test/ and the other python files in test/u-boot and the tests in
test/pytests or something like that.
Then we would have:
from tests import some_file (*)
like we do in tools
Also, I wouldn't call this 'massive' churn. Most files just have a
line or two changed, with test.py and test_ut.py getting more.
>
> A lot more of this type of namespace shortening which I believe is the
> normal Python-way of solving this issue.
It doesn't really, since 'util' might conflict with something. When
you have a set of related Python files, as with do in test/py it is
better to use a namespace. But even then, I think we would want a
shorter name.
Regards,
Simon
* "tests" is safe, I believe, since no modules use it it, e.g. it is
mentioned here:
[1] https://docs.pytest.org/en/stable/explanation/goodpractices.html#tests-as-part-of-application-code
More information about the U-Boot
mailing list