Skip to content

Commit 40a3b3b

Browse files
authored
Merge pull request #7 from BeyondEvil/use-pre-commit
Use pre-commit in project
2 parents edcd48d + 072278e commit 40a3b3b

File tree

12 files changed

+291
-132
lines changed

12 files changed

+291
-132
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ __pycache__
44
.cache
55
.DS_Store
66
.tox
7+
.eggs
8+
.vscode/
79
build
810
dist

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
3+
- repo: https://github.com/psf/black
4+
rev: stable
5+
hooks:
6+
- id: black
7+
args: [--safe, --quiet]
8+
language_version: python3
9+
10+
- repo: https://gitlab.com/pycqa/flake8
11+
rev: 3.7.7
12+
hooks:
13+
- id: flake8
14+
exclude: docs
15+
language_version: python3

.travis.yml

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,53 @@
11
language: python
2-
python:
3-
- 2.7
4-
- 3.6
5-
- pypy
6-
- pypy3
7-
- nightly
8-
matrix:
2+
jobs:
93
include:
10-
- python: 2.7
11-
env: TOXENV=flake8
12-
- python: 3.6
13-
env: TOXENV=flake8
14-
install:
15-
- pip install tox-travis
16-
script:
17-
- tox
18-
deploy:
19-
provider: pypi
20-
user: davehunt
21-
password:
22-
secure: "aSevNdJQLPH1S1TNaI+uSFdiZ+dEQkkvmLym5eA8vjvo0fV4FEQfjZg8rW69hfYAGA4EFkE3hQUs5IQIm5ug+A3FsMDjom4nAhCthq8g/5hviT+V6wVzoVdxf0JhlpLtDFteFTOKj5Z9PC/xhJJ/2/JrzmEwUwopiNtSNBdVwRXCOvb6L3aIU5DmTtuWokpBNmv4H2cdjCxwLROSlKdfFr4urUwiOst/A5W1HvdxWhEkQL7fLx/sUOHobYjkoL32miTpSHUJNH1L0G8uciMdtXTBY3HQ/uRfWaDs3iJ7Iwtk2hEB1ukPZiXtBX0FjTJXd71a4BvvG1FSQgeQ4zW1Fzf8Xz5qg0Z1Z+7DTFzekhd1AfcwDlr2Vh7xD6FCBSjFyAIXQ0n36mtoEfHDM6RQMQSQZm4j+4EOdFf9kfWsTn9XGWCr47r3qe+6SUzGSvHcD6LeoZZ2ZJjSk37vdQ0y28yvZr5goBFwY11MMjMVqLSA4mWhhueBWA7il9ciwfJbb6RThBfnHYdT8l4NRztkXz6QaW4KCJNVr3aE3MwPLzfux9JUUml//JUjuhChLpEvrAM6CRliZSawKdE9E2o5QOISt7yiEVdaxohAcfTkj5X+WTS5QBYjT/8+iV6KWDjghm/FH13/WZlcqMfC7be+EgXvqv3ffUanX7jnpzdg1sQ="
23-
distributions: sdist bdist_wheel
24-
on:
25-
tags: true
26-
repo: pytest-dev/pytest-base-url
27-
python: 3.6
4+
- stage: Tests
5+
name: Linting
6+
python: 3.7
7+
dist: xenial
8+
sudo: required
9+
env: TOXENV=linting
10+
11+
-
12+
python: 2.7
13+
env: TOXENV=py27
14+
15+
-
16+
python: 3.6
17+
env: TOXENV=py36
18+
19+
-
20+
python: 3.7
21+
dist: xenial
22+
sudo: required
23+
env: TOXENV=py37
24+
25+
-
26+
python: pypy
27+
env: TOXENV=pypy
28+
29+
-
30+
python: pypy3
31+
env: TOXENV=pypy3
32+
33+
- stage: deploy
34+
python: 3.7
35+
dist: xenial
36+
sudo: required
37+
install: skip
38+
script: skip
39+
deploy:
40+
provider: pypi
41+
user: davehunt
42+
password:
43+
secure: "aSevNdJQLPH1S1TNaI+uSFdiZ+dEQkkvmLym5eA8vjvo0fV4FEQfjZg8rW69hfYAGA4EFkE3hQUs5IQIm5ug+A3FsMDjom4nAhCthq8g/5hviT+V6wVzoVdxf0JhlpLtDFteFTOKj5Z9PC/xhJJ/2/JrzmEwUwopiNtSNBdVwRXCOvb6L3aIU5DmTtuWokpBNmv4H2cdjCxwLROSlKdfFr4urUwiOst/A5W1HvdxWhEkQL7fLx/sUOHobYjkoL32miTpSHUJNH1L0G8uciMdtXTBY3HQ/uRfWaDs3iJ7Iwtk2hEB1ukPZiXtBX0FjTJXd71a4BvvG1FSQgeQ4zW1Fzf8Xz5qg0Z1Z+7DTFzekhd1AfcwDlr2Vh7xD6FCBSjFyAIXQ0n36mtoEfHDM6RQMQSQZm4j+4EOdFf9kfWsTn9XGWCr47r3qe+6SUzGSvHcD6LeoZZ2ZJjSk37vdQ0y28yvZr5goBFwY11MMjMVqLSA4mWhhueBWA7il9ciwfJbb6RThBfnHYdT8l4NRztkXz6QaW4KCJNVr3aE3MwPLzfux9JUUml//JUjuhChLpEvrAM6CRliZSawKdE9E2o5QOISt7yiEVdaxohAcfTkj5X+WTS5QBYjT/8+iV6KWDjghm/FH13/WZlcqMfC7be+EgXvqv3ffUanX7jnpzdg1sQ="
44+
distributions: sdist bdist_wheel
45+
on:
46+
tags: true
47+
repo: pytest-dev/pytest-base-url
48+
49+
cache: pip
50+
51+
install: pip install tox
52+
53+
script: tox

Pipfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
pytest = "*"
8+
tox = "*"
9+
flake8 = "*"
10+
black = "*"
11+
pre-commit = "*"
12+
13+
[packages]
14+
pytest-base-url = {editable = true,path = "."}

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ To install pytest-base-url:
3737
3838
$ pip install pytest-base-url
3939
40+
Contributing
41+
------------
42+
43+
We welcome contributions.
44+
45+
To learn more, see `Development <https://github.com/pytest-dev/pytest-base-url/blob/master/development.rst>`_
46+
4047
Specifying a Base URL
4148
---------------------
4249

development.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Development
2+
===========
3+
4+
To contribute to `pytest-base-url` you can use `Pipenv`_ to manage
5+
a python virtual environment and `pre-commit <https://pre-commit.com/>`_ to help you with
6+
styling and formatting.
7+
8+
To setup the virtual environment and pre-commit, run:
9+
10+
.. code-block:: bash
11+
12+
$ pipenv install --dev
13+
$ pipenv run pre-commit install
14+
15+
If you're not using `Pipenv`_, to install `pre-commit`, run:
16+
17+
.. code-block:: bash
18+
19+
$ pip install pre-commit
20+
$ pre-commit install
21+
22+
23+
Automated Testing
24+
-----------------
25+
26+
All pull requests and merges are tested in `Travis CI <https://travis-ci.org/>`_
27+
based on the ``.travis.yml`` file.
28+
29+
Usually, a link to your specific travis build appears in pull requests, but if
30+
not, you can find it on the
31+
`pull requests page <https://travis-ci.org/pytest-dev/pytest-base-url/pull_requests>`_
32+
33+
The only way to trigger Travis CI to run again for a pull request, is to submit
34+
another change to the pull branch.
35+
36+
You can do this with `git commit --allow-empty`
37+
38+
Running Tests
39+
-------------
40+
41+
You will need `Tox <http://tox.testrun.org/>`_ installed to run the tests
42+
against the supported Python versions. If you're using `Pipenv`_ it will be
43+
installed for you.
44+
45+
With `Pipenv`_, run:
46+
47+
.. code-block:: bash
48+
49+
$ pipenv run tox
50+
51+
Otherwise, to install and run, do:
52+
53+
.. code-block:: bash
54+
55+
$ pip install tox
56+
$ tox
57+
58+
Releasing a new version
59+
-----------------------
60+
61+
Follow these steps to release a new version of the project:
62+
63+
1. Update your local master with the upstream master (``git pull --rebase upstream master``)
64+
2. Create a new branch and update ``CHANGES.rst`` with the new version, today's date, and all changes/new features
65+
3. Commit and push the new branch and then create a new pull request
66+
4. Wait for tests and reviews and then merge the branch
67+
5. Once merged, update your local master again (``git pull --rebase upstream master``)
68+
6. Tag the release with the new release version (``git tag v<new tag>``)
69+
7. Push the tag (``git push upstream --tags``)
70+
8. Done. You can monitor the progress on `Travis <https://travis-ci.org/pytest-dev/pytest-base-url/>`_

pytest_base_url/plugin.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,53 @@
1010
from requests.adapters import HTTPAdapter
1111

1212

13-
@pytest.fixture(scope='session')
13+
@pytest.fixture(scope="session")
1414
def base_url(request):
1515
"""Return a base URL"""
1616
config = request.config
17-
base_url = config.getoption('base_url')
17+
base_url = config.getoption("base_url")
1818
if base_url is not None:
1919
return base_url
2020

2121

22-
@pytest.fixture(scope='session', autouse=True)
22+
@pytest.fixture(scope="session", autouse=True)
2323
def _verify_url(request, base_url):
2424
"""Verifies the base URL"""
2525
verify = request.config.option.verify_base_url
2626
if base_url and verify:
2727
session = requests.Session()
28-
retries = Retry(backoff_factor=0.1,
29-
status_forcelist=[500, 502, 503, 504])
28+
retries = Retry(backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
3029
session.mount(base_url, HTTPAdapter(max_retries=retries))
3130
session.get(base_url)
3231

3332

3433
def pytest_configure(config):
35-
if hasattr(config, 'slaveinput'):
34+
if hasattr(config, "slaveinput"):
3635
return # xdist slave
37-
base_url = config.getoption('base_url') or config.getini('base_url')
36+
base_url = config.getoption("base_url") or config.getini("base_url")
3837
if base_url is not None:
3938
config.option.base_url = base_url
40-
if hasattr(config, '_metadata'):
41-
config._metadata['Base URL'] = base_url
39+
if hasattr(config, "_metadata"):
40+
config._metadata["Base URL"] = base_url
4241

4342

4443
def pytest_report_header(config, startdir):
45-
base_url = config.getoption('base_url')
44+
base_url = config.getoption("base_url")
4645
if base_url:
47-
return 'baseurl: {0}'.format(base_url)
46+
return "baseurl: {0}".format(base_url)
4847

4948

5049
def pytest_addoption(parser):
51-
parser.addini('base_url', help='base url for the application under test.')
50+
parser.addini("base_url", help="base url for the application under test.")
5251
parser.addoption(
53-
'--base-url',
54-
metavar='url',
55-
default=os.getenv('PYTEST_BASE_URL', None),
56-
help='base url for the application under test.')
52+
"--base-url",
53+
metavar="url",
54+
default=os.getenv("PYTEST_BASE_URL", None),
55+
help="base url for the application under test.",
56+
)
5757
parser.addoption(
58-
'--verify-base-url',
59-
action='store_true',
60-
default=not os.getenv('VERIFY_BASE_URL', 'false').lower() == 'false',
61-
help='verify the base url.')
58+
"--verify-base-url",
59+
action="store_true",
60+
default=not os.getenv("VERIFY_BASE_URL", "false").lower() == "false",
61+
help="verify the base url.",
62+
)

setup.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
from setuptools import setup
22

3-
setup(name='pytest-base-url',
4-
use_scm_version=True,
5-
description='pytest plugin for URL based testing',
6-
long_description=open('README.rst').read(),
7-
author='Dave Hunt',
8-
author_email='[email protected]',
9-
url='https://github.com/pytest-dev/pytest-base-url',
10-
packages=['pytest_base_url'],
11-
install_requires=[
12-
'pytest>=2.7.3',
13-
'requests>=2.9'],
14-
setup_requires=['setuptools_scm'],
15-
entry_points={'pytest11': ['base_url = pytest_base_url.plugin']},
16-
license='Mozilla Public License 2.0 (MPL 2.0)',
17-
keywords='py.test pytest base url mozilla automation',
18-
classifiers=[
19-
'Development Status :: 5 - Production/Stable',
20-
'Framework :: Pytest',
21-
'Intended Audience :: Developers',
22-
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
23-
'Operating System :: POSIX',
24-
'Operating System :: Microsoft :: Windows',
25-
'Operating System :: MacOS :: MacOS X',
26-
'Topic :: Software Development :: Quality Assurance',
27-
'Topic :: Software Development :: Testing',
28-
'Topic :: Utilities',
29-
'Programming Language :: Python',
30-
'Programming Language :: Python :: 2.7',
31-
'Programming Language :: Python :: 3.6',
32-
'Programming Language :: Python :: Implementation :: CPython',
33-
'Programming Language :: Python :: Implementation :: PyPy'])
3+
setup(
4+
name="pytest-base-url",
5+
use_scm_version=True,
6+
description="pytest plugin for URL based testing",
7+
long_description=open("README.rst").read(),
8+
author="Dave Hunt",
9+
author_email="[email protected]",
10+
url="https://github.com/pytest-dev/pytest-base-url",
11+
packages=["pytest_base_url"],
12+
install_requires=["pytest>=2.7.3", "requests>=2.9"],
13+
setup_requires=["setuptools_scm"],
14+
entry_points={"pytest11": ["base_url = pytest_base_url.plugin"]},
15+
license="Mozilla Public License 2.0 (MPL 2.0)",
16+
keywords="py.test pytest base url mozilla automation",
17+
classifiers=[
18+
"Development Status :: 5 - Production/Stable",
19+
"Framework :: Pytest",
20+
"Intended Audience :: Developers",
21+
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
22+
"Operating System :: POSIX",
23+
"Operating System :: Microsoft :: Windows",
24+
"Operating System :: MacOS :: MacOS X",
25+
"Topic :: Software Development :: Quality Assurance",
26+
"Topic :: Software Development :: Testing",
27+
"Topic :: Utilities",
28+
"Programming Language :: Python",
29+
"Programming Language :: Python :: 2.7",
30+
"Programming Language :: Python :: 3.6",
31+
"Programming Language :: Python :: Implementation :: CPython",
32+
"Programming Language :: Python :: Implementation :: PyPy",
33+
],
34+
)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
pytest_plugins = 'pytester'
5+
pytest_plugins = "pytester"

0 commit comments

Comments
 (0)