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

Now you can run separate mypy test modules 🎉 #11668

Merged
merged 4 commits into from
Dec 7, 2021
Merged

Now you can run separate mypy test modules 🎉 #11668

merged 4 commits into from
Dec 7, 2021

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Dec 5, 2021

One test is failing right now on purpose, so you can take a look on how new namespaces work.
I will fix it in the next commit, I hope the logs will be preserved for some time to see them.

Here's a quick recap of everything in this PR:

  • Here's how collect tree looks like: Meta issue: improving test runner #11662 (comment)
  • You can now run a single .test file with mypy/test/testcheck.py::TypeCheckSuite::check-basic.test
  • Single test will now be mypy/test/testcheck.py::TypeCheckSuite::check-basic.test::testAssignmentAndVarDef

Screenshots:
Снимок экрана 2021-12-06 в 1 08 08
Снимок экрана 2021-12-06 в 1 08 23
Снимок экрана 2021-12-06 в 1 15 00

Refs #11662

@sobolevn sobolevn mentioned this pull request Dec 5, 2021
3 tasks
@sobolevn
Copy link
Member Author

sobolevn commented Dec 5, 2021

@sobolevn
Copy link
Member Author

sobolevn commented Dec 5, 2021

Test numbers:

I hope that the time difference is caused by GitHub Action runner fluctuations and not my changes 🙂

Update: previous failing commit took ====== 1 failed, 9640 passed, 370 skipped, 7 xfailed in 832.98s (0:13:52) ======, which hopefully prooves my point about GitHub runners.

I am also going to friendly ping @bluetech as pytest's core dev and mypy contributor. Maybe you would have some time to give this PR a quick review? 🙂

@bluetech
Copy link
Contributor

bluetech commented Dec 6, 2021

Nice! Whenever I worked on mypy I did the "comment out the other files" bit which is annoying.

My only suggestion is to not make DataFileCollector a pytest.Class since it's not a class, really:

diff --git a/mypy/test/data.py b/mypy/test/data.py
index 559b5be2a..65fb26735 100644
--- a/mypy/test/data.py
+++ b/mypy/test/data.py
@@ -247,7 +247,7 @@ class DataDrivenTestCase(pytest.Item):
         # TODO: add a better error message for when someone uses skip and xfail at the same time
         elif self.xfail:
             self.add_marker(pytest.mark.xfail)
-        suite = self.parent.obj()
+        suite = self.getparent(DataSuiteCollector).obj()
         suite.setup()
         try:
             suite.run_case(self)
@@ -609,11 +609,12 @@ class DataSuiteCollector(pytest.Class):
             yield DataFileCollector.from_parent(parent=self, name=data_file)
 
 
-class DataFileCollector(pytest.Class):
+class DataFileCollector(pytest.Collector):
     """Represents a single `.test` data driven test file.
 
     More context: https://github.com/python/mypy/issues/11662
     """
+    parent: DataSuiteCollector
 
     @classmethod  # We have to fight with pytest here:
     def from_parent(  # type: ignore[override]
@@ -623,14 +624,13 @@ class DataFileCollector(pytest.Class):
         name: str,
     ) -> 'DataFileCollector':
         instance = super().from_parent(parent, name=name)  # type: ignore[no-untyped-call]
-        instance.obj = parent.obj  # We need to copy `DataSuite` object deeper.
         return instance
 
     def collect(self) -> Iterator['DataDrivenTestCase']:
         yield from split_test_cases(
             parent=self,
-            suite=self.obj,
-            file=os.path.join(self.obj.data_prefix, self.name),
+            suite=self.parent.obj,
+            file=os.path.join(self.parent.obj.data_prefix, self.name),
         )
 
 

@sobolevn
Copy link
Member Author

sobolevn commented Dec 6, 2021

Thank you! Fixed!

@hauntsaninja hauntsaninja merged commit 01e6aba into python:master Dec 7, 2021
@hauntsaninja
Copy link
Collaborator

This is great, thank you all! :-)

tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants