Skip to content

Rewrite testfiles to have multiversion testing locally#165

Closed
furtib wants to merge 6 commits intoEricsson:mainfrom
furtib:refactor-testing
Closed

Rewrite testfiles to have multiversion testing locally#165
furtib wants to merge 6 commits intoEricsson:mainfrom
furtib:refactor-testing

Conversation

@furtib
Copy link
Contributor

@furtib furtib commented Jan 22, 2026

Why:
We have no automated way to run tests for multiple Bazel versions.

What:

  • Add test_all_bazel_version.py to change the .bazelversion file's contents between running the tests.
  • Add usage guide to README.md

Addresses:
none

@furtib furtib requested review from Szelethus and nettle January 22, 2026 12:08
@furtib furtib self-assigned this Jan 22, 2026
@furtib furtib added enhancement New feature or request CI 📦 test ☑️ Adding or refactoring tests labels Jan 22, 2026
Copy link
Collaborator

@nettle nettle left a comment

Choose a reason for hiding this comment

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

Very good initiative @furtib!
But, sorry, test runner is really bad idea.
To move forward, may I suggest splitting this patch to 2:

  1. This one to actually address multiversion testing locally
  2. New one to re-implement tests that they clean after themselves without external cleaners

If I may, the following might help for the second part:

class TemporaryDir:
    """
    Safely creates and destroys temporary folder
    """
    def __init__(self):
        self._temp_dir = None

    def __enter__(self):
        self._temp_dir = tempfile.mkdtemp()
        logging.debug("Created %s", self._temp_dir)
        return self._temp_dir

    def __exit__(self, tipe, value, traceback):
        shutil.rmtree(self._temp_dir)
        logging.debug("Removed %s", self._temp_dir)

# See the License for the specific language governing permissions and
# limitations under the License.

git clone --recurse https://github.com/jbeder/yaml-cpp.git test-proj
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was wondering why do we need --recurse?
Does this repo have submodules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just stayed in from the original script.

Comment on lines 20 to 21
git reset --hard
git clean -fd
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess rm -rf test-proj is much safer.
Actually, we must always clean up after test, but that's different discussion

# See the License for the specific language governing permissions and
# limitations under the License.

python3 test_runner.py foss @a
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo?

Comment on lines 2 to 7
This file runs tests.
For unittest pass `unit` as parameter
For FOSS tests pass `foss` as parameter
For verbosity use `-vvv`
To clean up FOSS test artifacts use `--clean`
To run the specified tests on all supported Bazel versions use `--all`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm strictly against any test runners and wrappers around wrappers :)
If we cannot run python unittests via standard python -m unittest, if we need pre-initialization, if tests do not clean themselves, if we need special cleaner, then something is definitely wrong.

@furtib
Copy link
Contributor Author

furtib commented Jan 26, 2026

I reworked it a bit, removed anything that is not strictly necessary for automated testing of multiple Bazel versions.

I may be short-sighted, but I don't know how I could do this without the help of a wrapper around python3 -m unittests discover @a. However, for regular testing, python3 -m unittests discover @a should and does work!

@furtib furtib requested a review from nettle January 26, 2026 16:52
Copy link
Collaborator

@nettle nettle left a comment

Choose a reason for hiding this comment

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

To me this patch is quite controversial.
Here are my reasons:

  1. I think it does not help much in running tests locally
  2. It does aim only at bazel multiversion, but not other tools (at least CodeChecker)
  3. It implies we always have bazelisk instead of bazel which not the case
  4. It makes tests depend on .github which is really not good
  5. It adds more unnecessary layering which hides testing functionality

@@ -1,2 +1,17 @@
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the following shebang is recommended:

#!/usr/bin/env bash

@@ -1,2 +1,17 @@
#!/bin/bash
python3 -m unittest discover unit $@
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we introduce test/test_foss.sh then this file should be test/test_unit.sh

Comment on lines +3 to +15
# Copyright 2023 Ericsson AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this is not much needed for "convenience" scripts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have the license in empts __init__.py files too.
Better safe than sorry.

Comment on lines +16 to +21
This script replaces the content of the .bazelversion file
from .github/bazel_version.json and runs the equivalent of
python3 -m unittest discover @a
For unittest pass `unit` as parameter
For FOSS tests pass `foss` as parameter #TODO: Add cleanup between FOSS runs
For verbosity use `-vvv`
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be honest I dont understand the meaning of this so far...
Looks like something which depends on bazelisk. Am I right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this does depend on bazelisk. My goal was to make this script as simple as it can get. And to be honest, I didn't think testing multiple Bazel versions without bazelisk was even possible.

@furtib
Copy link
Contributor Author

furtib commented Jan 27, 2026

Now that we seem to be on board with Mise (#132), is this patch still relevant?

@nettle
Copy link
Collaborator

nettle commented Jan 27, 2026

Now that we seem to be on board with Mise (#132), is this patch still relevant?

Probably not...
I would vote to put this back to draft or cancel

@furtib
Copy link
Contributor Author

furtib commented Jan 28, 2026

Closing this PR since this issue has been addressed in #132.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI 📦 enhancement New feature or request test ☑️ Adding or refactoring tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants