pytest-picked icon indicating copy to clipboard operation
pytest-picked copied to clipboard

"Guess" the test file from changed module

Open anapaulagomes opened this issue 6 years ago • 4 comments

Let's say you've changed house/serializers.py. Would be nice to run the tests of house/test_serializers.py or even the tests that were related.

To keep in mind:

  • There is an option on pytest to specify test paths

anapaulagomes avatar May 27 '18 11:05 anapaulagomes

Pytest already knows which all tests to run. So maybe if we introspect the code and identify which all tests are using the methods we just changed, this can be done. What do you think?

iamkhush avatar May 27 '18 14:05 iamkhush

It's possible to check through git diff as well:

Change in a method

diff --git a/tests/test_pytest_picked.py b/tests/test_pytest_picked.py
index e63dc00..c71fe1c 100644
--- a/tests/test_pytest_picked.py
+++ b/tests/test_pytest_picked.py
@@ -5,6 +5,7 @@ from pytest_picked import _affected_tests

 def test_shows_affected_tests(testdir):
     result = testdir.runpytest("--picked")
+    # bla bla bla

     assert "Changed test files..." in result.stdout.str()
     assert "Changed test folders..." in result.stdout.str()

Change in a class

diff --git a/tests/test_bot.py b/tests/test_bot.py
index 78fe572..50e6436 100644
--- a/tests/test_bot.py
+++ b/tests/test_bot.py
@@ -19,6 +19,7 @@ class TestBotConnection:
     @patch('grandma.bot.SlackClient.rtm_connect')
     def test_connect_on_slack_api(self, rtm_connect_mock, api_call_mock, bot):
         expected_user_id = 'A1B999WWW'
+        # bla bla bla

         rtm_connect_mock.return_value = True
         api_call_mock.return_value = {'user_id': expected_user_id}

I'll take a look on pytest code to check if there are other way to do it. If possible, feel free to bring examples for this discussion!

anapaulagomes avatar May 27 '18 16:05 anapaulagomes

I think would be good to also run the tests that use the class/function which was modified

marcelotrevisani avatar Jun 11 '18 09:06 marcelotrevisani

I hope it's not too impolite to point out 2 projects which already implement this: https://github.com/ChrisBeaumont/smother http://github.com/tarpas/pytest-testmon

tarpas avatar Oct 11 '19 15:10 tarpas