Repository: conan-io/conan
Pull request #17745 (2025-02-10 12:28:22)

Fix test issues and warnings
Changelog: omit
Docs: omit

Close https://github.com/conan-io/conan/issues/17736#event-16228685511

- [x] Remove the coverage output from the logs, too verbose there, they are in the web already
- [x] Fix the warnings in the test suite due to non escaped strings in regex and the like
- [x] Reduce the duration report to the slowest 10 tests
- [ ] Fix the webob warning, might need to update the test-dependency WebTest


Patch:
diff --git a/conan/tools/sbom/cyclonedx.py b/conan/tools/sbom/cyclonedx.py
index 967e45215..22c308a93 100644
--- a/conan/tools/sbom/cyclonedx.py
+++ b/conan/tools/sbom/cyclonedx.py
@@ -1,6 +1,6 @@
 
 
-def cyclonedx_1_4(graph, add_build=False, add_tests=False, **kwargs):
+def cyclonedx_1_4(graph, name=None, add_build=False, add_tests=False, **kwargs):
     """
     (Experimental) Generate cyclone 1.4 sbom with json format
     """
@@ -10,6 +10,9 @@ def cyclonedx_1_4(graph, add_build=False, add_tests=False, **kwargs):
 
     has_special_root_node = not (getattr(graph.root.ref, "name", False) and getattr(graph.root.ref, "version", False) and getattr(graph.root.ref, "revision", False))
     special_id = str(uuid.uuid4())
+
+    name_default = getattr(graph.root.ref, "name", False) or "conan-sbom"
+    name_default += f"/{graph.root.ref.version}" if bool(getattr(graph.root.ref, "version", False)) else ""
     components = [node for node in graph.nodes if (node.context == "host" or add_build) and (not node.test or add_tests)]
     if has_special_root_node:
         components = components[1:]
@@ -58,7 +61,7 @@ def cyclonedx_1_4(graph, add_build=False, add_tests=False, **kwargs):
             "component": {
                 "author": "Conan",
                 "bom-ref": special_id if has_special_root_node else f"pkg:conan/{c.name}@{c.ref.version}?rref={c.ref.revision}",
-                "name": graph.root.conanfile.display_name,
+                "name": name if name else name_default,
                 "type": "library"
             },
             "timestamp": f"{datetime.fromtimestamp(time.time(), tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}",


Test patch:
diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml
index 666b10d11..86127f8d0 100644
--- a/.github/actions/test-coverage/action.yml
+++ b/.github/actions/test-coverage/action.yml
@@ -11,7 +11,7 @@ inputs:
     required: true
 
   duration:
-    description: 'Tests maximum duration'
+    description: 'Show N slowest test durations (N=0 for all)'
     required: true
     default: '10'
 
@@ -30,7 +30,7 @@ runs:
         if: ${{ inputs.tests }}
         shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
         run: |
-          pytest ${{ inputs.tests }} --durations=${{ inputs.duration }} -n ${{ inputs.workers }} ${{ github.ref == 'refs/heads/develop2' && '--cov=conan --cov=conans --cov=test --cov-report=term-missing:skip-covered' || '' }}
+          pytest ${{ inputs.tests }} --durations=${{ inputs.duration }} -n ${{ inputs.workers }} ${{ github.ref == 'refs/heads/develop2' && '--cov=conan --cov=conans --cov=test --cov-report=' || '' }}
 
       - name: Rename coverage file
         if: github.ref == 'refs/heads/develop2'
diff --git a/.github/workflows/linux-tests.yml b/.github/workflows/linux-tests.yml
index 1df2d43d1..7e447a6c3 100644
--- a/.github/workflows/linux-tests.yml
+++ b/.github/workflows/linux-tests.yml
@@ -88,7 +88,6 @@ jobs:
           python-version: ${{ matrix.python-version }}
           test-type: ${{ matrix.test-type }}
           tests: test/${{ matrix.test-type }}
-          duration: 20
 
   linux_docker_tests:
     needs: build_container
@@ -120,5 +119,4 @@ jobs:
           python-version: ${{ matrix.python-version }}
           test-type: docker
           tests: '-m docker_runner -rs'
-          duration: 20
           workers: 1
diff --git a/.github/workflows/osx-tests.yml b/.github/workflows/osx-tests.yml
index 13eab0aab..339ab9f72 100644
--- a/.github/workflows/osx-tests.yml
+++ b/.github/workflows/osx-tests.yml
@@ -172,4 +172,3 @@ jobs:
           python-version: ${{ matrix.python-version }}
           test-type: ${{ matrix.test-type }}
           tests: test/${{ matrix.test-type }}
-          duration: 20
diff --git a/.github/workflows/win-tests.yml b/.github/workflows/win-tests.yml
index 71775b251..c67b62eab 100644
--- a/.github/workflows/win-tests.yml
+++ b/.github/workflows/win-tests.yml
@@ -54,7 +54,6 @@ jobs:
           python-version: ${{ matrix.python-version }}
           test-type: unit-integration
           tests: test/unittests test/integration
-          duration: 100
 
   functional_tests:
     runs-on: windows-2022
@@ -249,4 +248,3 @@ jobs:
           python-version: ${{ matrix.python-version }}
           test-type: functional
           tests: test/functional
-          duration: 100
diff --git a/test/functional/sbom/test_cyclonedx.py b/test/functional/sbom/test_cyclonedx.py
index 3c1b80a0b..b24f3beb7 100644
--- a/test/functional/sbom/test_cyclonedx.py
+++ b/test/functional/sbom/test_cyclonedx.py
@@ -138,7 +138,7 @@ from conan.api.output import ConanOutput
 from conan.tools.sbom import cyclonedx_1_4
 
 def post_generate(conanfile):
-    sbom_cyclonedx_1_4 = cyclonedx_1_4(conanfile.subgraph)
+    sbom_cyclonedx_1_4 = cyclonedx_1_4(conanfile.subgraph, name=%s)
     generators_folder = conanfile.generators_folder
     file_name = "sbom.cdx.json"
     os.mkdir(os.path.join(generators_folder, "sbom"))
@@ -151,7 +151,7 @@ def post_generate(conanfile):
 def hook_setup_post_generate():
     tc = TestClient()
     hook_path = os.path.join(tc.paths.hooks_path, "hook_sbom.py")
-    save(hook_path, sbom_hook_post_generate)
+    save(hook_path, sbom_hook_post_generate % "None")
     return tc
 
 def test_sbom_generation_install_requires(hook_setup_post_generate):
@@ -199,3 +199,17 @@ def test_sbom_generation_install_path_txt(hook_setup_post_generate):
     #foo -> dep
     tc.run("install .")
     assert os.path.exists(os.path.join(tc.current_folder, "sbom", "sbom.cdx.json"))
+
+@pytest.mark.parametrize("name, result", [
+    ("None", "conan-sbom"),
+    ('"custom-name"', "custom-name")
+])
+def test_sbom_generation_custom_name(name, result):
+    tc = TestClient()
+    hook_path = os.path.join(tc.paths.hooks_path, "hook_sbom.py")
+    save(hook_path, sbom_hook_post_generate % name)
+
+    tc.save({"conanfile.py": GenConanfile()})
+    tc.run("install .")
+    assert os.path.exists(os.path.join(tc.current_folder, "sbom", "sbom.cdx.json"))
+    assert f'"name": "{result}"' in tc.load(os.path.join(tc.current_folder, "sbom", "sbom.cdx.json"))
diff --git a/test/integration/configuration/conf/test_conf_copy.py b/test/integration/configuration/conf/test_conf_copy.py
index 46597afd8..2ebfb06ba 100644
--- a/test/integration/configuration/conf/test_conf_copy.py
+++ b/test/integration/configuration/conf/test_conf_copy.py
@@ -18,7 +18,7 @@ def test_copy_conaninfo_conf():
     assert "tools.deployer:symlinks" in result
     assert "user.myconf:cmake-test" in result
 
-    pattern = ["tools\..*"]
+    pattern = [r"tools\..*"]
     conf.define("tools.info.package_id:confs", pattern)
     result = conf.copy_conaninfo_conf().dumps()
     assert "tools.info.package_id:confs=%s" % pattern in result
diff --git a/test/integration/toolchains/microsoft/test_nmakedeps.py b/test/integration/toolchains/microsoft/test_nmakedeps.py
index 39a93a107..4eee33c80 100644
--- a/test/integration/toolchains/microsoft/test_nmakedeps.py
+++ b/test/integration/toolchains/microsoft/test_nmakedeps.py
@@ -41,11 +41,11 @@ def test_nmakedeps():
     bat_file = client.load("conannmakedeps.bat")
     # Checking that defines are added to CL
     for flag in (
-        '/D"TEST_DEFINITION1"', '/D"TEST_DEFINITION2#0"',
-        '/D"TEST_DEFINITION3#"', '/D"TEST_DEFINITION4#"foo""',
-        '/D"TEST_DEFINITION5#"__declspec\(dllexport\)""',
-        '/D"TEST_DEFINITION6#"foo bar""',
-        '/D"TEST_DEFINITION7#7"'
+        r'/D"TEST_DEFINITION1"', '/D"TEST_DEFINITION2#0"',
+        r'/D"TEST_DEFINITION3#"', '/D"TEST_DEFINITION4#"foo""',
+        r'/D"TEST_DEFINITION5#"__declspec\(dllexport\)""',
+        r'/D"TEST_DEFINITION6#"foo bar""',
+        r'/D"TEST_DEFINITION7#7"'
     ):
         assert re.search(fr'set "CL=%CL%.*\s{flag}(?:\s|")', bat_file)
     # Checking that libs and system libs are added to _LINK_
diff --git a/test/unittests/tools/files_patch_test.py b/test/unittests/tools/files_patch_test.py
index cdfb1ea8f..6d7c95e56 100644
--- a/test/unittests/tools/files_patch_test.py
+++ b/test/unittests/tools/files_patch_test.py
@@ -90,7 +90,7 @@ class ToolsFilesPatchTest(unittest.TestCase):
             class PatchConan(ConanFile):
                 def source(self):
                     patch(self, self.source_folder, "example.patch", strip=1)""")
-        patch = dedent("""
+        patch = dedent(r"""
             --- a\src\oldfile
             +++ b/dev/null
             @@ -0,1 +0,0 @@