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

"Guess" the test file from changed module #3

Open
anapaulagomes opened this issue May 27, 2018 · 4 comments
Open

"Guess" the test file from changed module #3

anapaulagomes opened this issue May 27, 2018 · 4 comments

Comments

@anapaulagomes
Copy link
Owner

@anapaulagomes anapaulagomes commented May 27, 2018

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
@iamkhush
Copy link
Contributor

@iamkhush iamkhush commented May 27, 2018

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?

@anapaulagomes
Copy link
Owner Author

@anapaulagomes anapaulagomes commented May 27, 2018

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!

@marcelotrevisani
Copy link

@marcelotrevisani marcelotrevisani commented Jun 11, 2018

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

@tarpas
Copy link

@tarpas tarpas commented Oct 11, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.