archive mirror
 help / color / mirror / Atom feed
From: Daniel Latypov <>
	Daniel Latypov <>
Subject: [PATCH v2] kunit: tool: fix newly introduced typechecker errors
Date: Wed, 15 Dec 2021 12:39:23 -0800	[thread overview]
Message-ID: <> (raw)

After upgrading mypy and pytype from pip, we see 2 new errors when
running ./tools/testing/kunit/

Error #1: mypy and pytype
They now deduce that importlib.util.spec_from_file_location() can return
None and note that we're not checking for this.

We validate that the arch is valid (i.e. the file exists) beforehand.
Add in an `asssert spec is not None` to appease the checkers.

Error #2: pytype bug
It doesn't like `from datetime import datetime`, specifically that a
type shares a name with a module.

We can workaround this by either
* renaming the import or just using `import datetime`
* passing the new `--fix-module-collisions` flag to pytype.

We pick the first option for now because
* the flag is quite new, only in the 2021.11.29 release.
* I'd prefer if people can just run `pytype <file>`

Signed-off-by: Daniel Latypov <>
Reviewed-by: Brendan Higgins <>
v1 -> v2: rebase on top of linx-kselftest kunit branch.
Only conflict was a deleted import in
 tools/testing/kunit/ | 1 +
 tools/testing/kunit/ | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/testing/kunit/ b/tools/testing/kunit/
index 12085e04a80c..44bbe54f25f1 100644
--- a/tools/testing/kunit/
+++ b/tools/testing/kunit/
@@ -209,6 +209,7 @@ def get_source_tree_ops_from_qemu_config(config_path: str,
 	# exists as a file.
 	module_path = '.' + os.path.join(os.path.basename(QEMU_CONFIGS_DIR), os.path.basename(config_path))
 	spec = importlib.util.spec_from_file_location(module_path, config_path)
+	assert spec is not None
 	config = importlib.util.module_from_spec(spec)
 	# See for context.
 	assert isinstance(spec.loader,
diff --git a/tools/testing/kunit/ b/tools/testing/kunit/
index 66a7f2fb314a..05ff334761dd 100644
--- a/tools/testing/kunit/
+++ b/tools/testing/kunit/
@@ -12,7 +12,7 @@
 from __future__ import annotations
 import re
-from datetime import datetime
+import datetime
 from enum import Enum, auto
 from functools import reduce
 from typing import Iterable, Iterator, List, Optional, Tuple
@@ -517,7 +517,7 @@ ANSI_LEN = len(red(''))
 def print_with_timestamp(message: str) -> None:
 	"""Prints message with timestamp at beginning."""
-	print('[%s] %s' % ('%H:%M:%S'), message))
+	print('[%s] %s' % ('%H:%M:%S'), message))
 def format_test_divider(message: str, len_message: int) -> str:

base-commit: 1ee2ba89bea86d6389509e426583b49ac19b86f2

                 reply	other threads:[~2021-12-15 20:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).