Skip to content

Commit

Permalink
resolved all conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
omkarkhatavkar committed Dec 12, 2020
2 parents ef6acd3 + ad4c1b2 commit 80d712c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: anapaulagomes
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- Add fixture for git user configuration
- Skip "Publish to Test PyPi" workflow when there is no change on setup.py

## [0.4.5] - 2020-11-17
### Added
- Add optional parameter, `--parent-branch`, to point to different parent branch (#113)

## [0.4.4] - 2020-03-21
### Fixed
- Fix branch mode for renaming cases (#77)
Expand Down
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ Usage

$ pytest --picked --mode=unstaged # default

$ pytest --picked --mode=onlychanged # runs only updated/modified/added unstaged tests based in git diff
$ pytest --picked --mode=branch --parent-branch=main # if your parent branch differs from "master"

$ pytest --picked --mode=onlychanged # runs only updated/modified/added unstaged tests based in git diff


Features
--------
Expand Down
6 changes: 5 additions & 1 deletion pytest_picked/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ def parser(self, candidate):


class Branch(Mode):
def __init__(self, test_file_convention, parent_branch="master"):
super().__init__(test_file_convention)
self.parent_branch = parent_branch

def command(self):
return ["git", "diff", "--name-status", "--relative", "master"]
return ["git", "diff", "--name-status", "--relative", self.parent_branch]

def parser(self, candidate):
"""
Expand Down
9 changes: 9 additions & 0 deletions pytest_picked/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ def pytest_addoption(parser):
required=False,
help="Options: unstaged, branch, onlychanged",
)
group.addoption(
"--parent-branch",
action="store",
dest="parent_branch",
default="master",
required=False,
help="The main branch of your repo (master, main, trunk, etc)",
)


def _get_affected_paths(config):
picked_mode = config.getoption("picked_mode")
parent_branch = config.getoption("parent_branch")
test_file_convention = config._getini("python_files") # pylint: disable=W0212
test_class_convention = config._getini("python_classes") # pylint: disable=W0212
test_function_convention = config._getini(
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest==6.1.0
pytest==6.1.2
10 changes: 5 additions & 5 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt
black==19.10b0
flake8==3.8.3
isort==5.5.4
pre-commit==2.7.1
tox==3.20.0
black==20.8b1
flake8==3.8.4
isort==5.6.4
pre-commit==2.9.2
tox==3.20.1
9 changes: 9 additions & 0 deletions tests/test_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ def test_should_return_command_that_list_all_changed_files(self):
"master",
]

def test_should_return_command_that_list_all_changed_files_for_different_branch(
self,
):
mode = Branch([], "main")
command = mode.command()

assert isinstance(command, list)
assert mode.command() == ["git", "diff", "--name-status", "--relative", "main"]

@pytest.mark.parametrize(
"line,expected_line",
[
Expand Down
27 changes: 27 additions & 0 deletions tests/test_pytest_picked.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,30 @@ def test_sth():
)
result = testdir.runpytest("--picked=first", "-v")
result.stdout.re_match_lines(["test_access.py.+", "test_flows.py.+"])


def test_should_accept_different_parent_branch_param(testdir, tmpdir):
with patch("pytest_picked.modes.subprocess.run") as subprocess_mock:
output = b"M test_flows.py\nA test_serializers.py\n"
subprocess_mock.return_value.stdout = output

result = testdir.runpytest("--picked", "--mode=branch", "--parent-branch=main")
testdir.makepyfile(
".py",
test_flows="""
def test_sth():
assert True
""",
test_serializers="""
def test_sth():
assert True
""",
)
tmpdir.mkdir("tests")
result.stdout.fnmatch_lines(
[
"Changed test files... 2. "
+ "['test_flows.py', 'test_serializers.py']",
"Changed test folders... 0. []",
]
)

0 comments on commit 80d712c

Please sign in to comment.