Skip to content

Commit

Permalink
Add changed files/folders to the test collection (#8)
Browse files Browse the repository at this point in the history
* Add changed files/folders to the test collection

* Add pytest cache

* Update CHANGELOG
  • Loading branch information
anapaulagomes authored Jul 8, 2018
1 parent a57d0c2 commit 0b6b933
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ target/
# pyenv
.python-version

# pytest
.pytest_cache/
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Changelog

## [Unreleased]
### Added
- Filter tests according with pytest file convention
- Only collects the tests from `git status`

## [0.1.0] - 2018-05-24
### Added
- Run the tests according with changed files

[Unreleased]: https://github.com/anapaulagomes/pytest-picked/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/anapaulagomes/pytest-picked/compare/v0.3.0...v0.1.0
[0.1.0]: https://github.com/anapaulagomes/pytest-picked/compare/a5d86647c511ea56d0d4c42b416b2d7bac8111f6...v0.1.0
20 changes: 3 additions & 17 deletions pytest_picked.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import subprocess

import _pytest.config
import _pytest


def pytest_addoption(parser):
Expand All @@ -14,27 +14,16 @@ def pytest_addoption(parser):
)


def pytest_collection_modifyitems(items, config):
def pytest_configure(config):
picked_plugin = config.getoption("picked")
if not picked_plugin:
return

test_file_convention = config._getini("python_files")
picked_files, picked_folders = _affected_tests(test_file_convention)
config.args = picked_files + picked_folders
_display_affected_tests(config, picked_files, picked_folders)

to_be_tested = []
for item in items:
location = item.location[0]
if location in picked_files:
to_be_tested.append(item)
else:
for folder in picked_folders:
if location.startswith(folder):
to_be_tested.append(item)
break
items[:] = to_be_tested


def _display_affected_tests(config, files, folders):
writer = _pytest.config.create_terminal_writer(config)
Expand Down Expand Up @@ -95,6 +84,3 @@ def _get_git_status():
command = ["git", "status", "--short"]
output = subprocess.run(command, stdout=subprocess.PIPE)
return output.stdout.decode("utf-8")


# TODO branch changed files git diff --name-only master

0 comments on commit 0b6b933

Please sign in to comment.