├── .gitignore ├── LICENSE.txt ├── MANIFEST.in ├── README.md ├── debian ├── .debhelper │ └── generated │ │ └── python3-pytest-pythonpath │ │ └── installed-by-dh_installdocs ├── changelog ├── compat ├── control ├── copyright └── rules ├── pytest.ini ├── pytest_pythonpath.py ├── requirements.txt ├── setup.py ├── test_path ├── __init__.py ├── apps │ ├── __init__.py │ └── test_package │ │ ├── __init__.py │ │ └── hey.py ├── libs │ ├── __init__.py │ └── hello.py ├── sitedir1 │ ├── __init__.py │ └── yo.py ├── sitedir2 │ ├── __init__.py │ ├── hola.py │ └── test.pth └── sitedir3 │ ├── __init__.py │ └── pow.py └── test_pythonpath.py /.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | .DS_Store 3 | .noseids 4 | *.pyc 5 | *.log 6 | *.swp 7 | pip.log 8 | local_settings.py 9 | 10 | virenv 11 | .idea 12 | build 13 | dist 14 | *.egg-info -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Eric Palakovich Carr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE.txt 2 | include test_pythonpath.py 3 | include pytest.ini 4 | recursive-include test_path * 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pytest-pythonpath 2 | ================= 3 | 4 | **NOTE:** This plugin is obsolete as of pytest 7.0.0. Thanks to [this PR](https://github.com/pytest-dev/pytest/pull/9134) from [Brian Okken](https://github.com/okken), you can now modify the PYTHONPATH using the `pythonpath` configuration option. See documentation here: https://docs.pytest.org/en/7.0.x/reference/reference.html#confval-pythonpath 5 | 6 | This is a py.test plugin for adding to the PYTHONPATH from the pytests.ini file before tests run. 7 | 8 | Installation 9 | ------------ 10 | 11 | Install with pip:: 12 | 13 | pip install pytest-pythonpath 14 | 15 | Uninstall with pip:: 16 | 17 | pip uninstall pytest-pythonpath 18 | 19 | Usage 20 | ----- 21 | 22 | Add a line in your pytest.ini file with a key of `python_paths` and provide a space seperated list of paths 23 | you want inserted to the beginning of the PYTHONPATH before any tests run: 24 | 25 | [pytest] 26 | python_paths = your/path/apps your/path/libs 27 | 28 | If you'd like to have `.pth` files be processed too, use `site_dirs` instead: 29 | 30 | [pytest] 31 | site_dirs = your/path/apps your/path/libs 32 | 33 | This will cause the `addsitedir` function to be called on each path instead of a simple `sys.path.insert(0, path)`. 34 | Note that using the `site_dirs` will not place your specified paths in front of existing paths. 35 | 36 | Once this is added to your pytest.ini, you can use the py.test command as you normally would. 37 | -------------------------------------------------------------------------------- /debian/.debhelper/generated/python3-pytest-pythonpath/installed-by-dh_installdocs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericpalakovichcarr/pytest-pythonpath/01d92d9e426a96b8208c7b6a92baee3c9f836aea/debian/.debhelper/generated/python3-pytest-pythonpath/installed-by-dh_installdocs -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | python3-pytest-pythonpath (0.7.1-1) UNRELEASED; urgency=high 2 | 3 | * new package 4 | 5 | -- Jeff Cliff Sat, 25 Nov 2017 14:16:29 +0500 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------- # 2 | # DEBIAN PACKAGE CONTROL FILE # 3 | # # 4 | # This file is a Debian control file. For more information on the config in # 5 | # this file, please run `man deb-control`. # 6 | # ------------------------------------------------------------------------- # 7 | 8 | Source: python3-pytest-pythonpath 9 | Section: contrib/python 10 | Priority: extra 11 | Maintainer: Jeff Cliff 12 | Build-Depends: debhelper(>= 9), python3, dh-python, python3-all, python3-pytest(>= 2.5.2) 13 | Standards-Version: 3.9.5 14 | 15 | Package: python3-pytest-pythonpath 16 | Architecture: any 17 | Pre-Depends: dpkg (>= 1.16.1), python3, python3-pytest(>= 2.5.2) 18 | Depends: make, python3-pytest 19 | Description: A py.test plugin for adding to the PYTHONPATH 20 | from pytest.ini 21 | 22 | 23 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: pytest-pythonpath 3 | Source: https://github.com/bigsassy/pytest-pythonpath 4 | 5 | Files: * 6 | Copyright: Copyright (c) 2014 Eric Palakovich Carr 7 | License: MIT 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | this software and associated documentation files (the "Software"), to deal in 10 | the Software without restriction, including without limitation the rights to 11 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | the Software, and to permit persons to whom the Software is furnished to do so, 13 | subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | 26 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #! /usr/bin/make -f 2 | 3 | export DH_VERBOSE = 1 4 | export PYBUILD_NAME = foo 5 | 6 | %: 7 | dh $@ --with python3 --buildsystem=pybuild 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | norecursedirs = virenv 3 | python_paths = test_path/apps test_path/libs 4 | site_dirs = test_path/sitedir1 test_path/sitedir2 5 | -------------------------------------------------------------------------------- /pytest_pythonpath.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import site 4 | 5 | import pytest 6 | 7 | 8 | def pytest_addoption(parser): 9 | # py.test has an issue where the cwd is not in the PYTHONPATH. Fix it here. 10 | if os.getcwd() not in sys.path: 11 | sys.path.insert(0, os.getcwd()) 12 | parser.addini("python_paths", type="pathlist", help="space seperated directory paths to add to PYTHONPATH via sys.path.insert(0, path)", 13 | default=[]) 14 | parser.addini("site_dirs", type="pathlist", help="space seperated directory paths to add to PYTHONPATH via site.addsitedir(path)", 15 | default=[]) 16 | 17 | 18 | @pytest.mark.tryfirst 19 | def pytest_load_initial_conftests(args, early_config, parser): 20 | for path in reversed(early_config.getini("python_paths")): 21 | sys.path.insert(0, str(path)) 22 | for path in early_config.getini("site_dirs"): 23 | site.addsitedir(str(path)) 24 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pytest>=2.5.2 2 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | description = 'pytest plugin for adding to the PYTHONPATH from command line or configs.' 4 | try: 5 | long_description = open("README.md").read() 6 | except: 7 | long_description = description 8 | 9 | setup( 10 | name='pytest-pythonpath', 11 | description=description, 12 | long_description=long_description, 13 | long_description_content_type='text/markdown', 14 | license='MIT', 15 | version='0.7.4', 16 | author='Eric Palakovich Carr', 17 | author_email='carreric@gmail.com', 18 | url='https://github.com/bigsassy/pytest-pythonpath', 19 | py_modules=['pytest_pythonpath'], 20 | entry_points={'pytest11': ['pythonpath = pytest_pythonpath']}, 21 | install_requires=['pytest>=2.5.2,<7'], 22 | python_requires='>=2.6, <4', 23 | classifiers=[ 24 | "Development Status :: 5 - Production/Stable", 25 | "Environment :: Plugins", 26 | "Framework :: Pytest", 27 | "Intended Audience :: Developers", 28 | "License :: OSI Approved :: MIT License", 29 | 'Programming Language :: Python :: 2', 30 | "Programming Language :: Python :: 2.6", 31 | "Programming Language :: Python :: 2.7", 32 | 'Programming Language :: Python :: 3', 33 | "Programming Language :: Python :: 3.0", 34 | "Programming Language :: Python :: 3.1", 35 | "Programming Language :: Python :: 3.2", 36 | "Programming Language :: Python :: 3.3", 37 | "Programming Language :: Python :: 3.4", 38 | "Programming Language :: Python :: 3.5", 39 | "Programming Language :: Python :: 3.6", 40 | "Programming Language :: Python :: 3.7", 41 | "Programming Language :: Python :: 3.8", 42 | "Programming Language :: Python :: 3.9", 43 | "Programming Language :: Python :: 3.10", 44 | "Topic :: Software Development :: Testing", 45 | ], 46 | ) 47 | -------------------------------------------------------------------------------- /test_path/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericpalakovichcarr/pytest-pythonpath/01d92d9e426a96b8208c7b6a92baee3c9f836aea/test_path/__init__.py -------------------------------------------------------------------------------- /test_path/apps/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericpalakovichcarr/pytest-pythonpath/01d92d9e426a96b8208c7b6a92baee3c9f836aea/test_path/apps/__init__.py -------------------------------------------------------------------------------- /test_path/apps/test_package/__init__.py: -------------------------------------------------------------------------------- 1 | def return_hi(): 2 | return "hi" -------------------------------------------------------------------------------- /test_path/apps/test_package/hey.py: -------------------------------------------------------------------------------- 1 | def return_hey(): 2 | return "hey" 3 | -------------------------------------------------------------------------------- /test_path/libs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericpalakovichcarr/pytest-pythonpath/01d92d9e426a96b8208c7b6a92baee3c9f836aea/test_path/libs/__init__.py -------------------------------------------------------------------------------- /test_path/libs/hello.py: -------------------------------------------------------------------------------- 1 | def return_hello(): 2 | return "hello" 3 | -------------------------------------------------------------------------------- /test_path/sitedir1/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'eric' 2 | -------------------------------------------------------------------------------- /test_path/sitedir1/yo.py: -------------------------------------------------------------------------------- 1 | def return_yo(): 2 | return "yo" 3 | -------------------------------------------------------------------------------- /test_path/sitedir2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericpalakovichcarr/pytest-pythonpath/01d92d9e426a96b8208c7b6a92baee3c9f836aea/test_path/sitedir2/__init__.py -------------------------------------------------------------------------------- /test_path/sitedir2/hola.py: -------------------------------------------------------------------------------- 1 | def return_hola(): 2 | return "hola" 3 | -------------------------------------------------------------------------------- /test_path/sitedir2/test.pth: -------------------------------------------------------------------------------- 1 | ../sitedir3 -------------------------------------------------------------------------------- /test_path/sitedir3/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'eric' 2 | -------------------------------------------------------------------------------- /test_path/sitedir3/pow.py: -------------------------------------------------------------------------------- 1 | def return_pow(): 2 | return "pow" 3 | -------------------------------------------------------------------------------- /test_pythonpath.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | from test_package import return_hi, hey 5 | from hello import return_hello 6 | from yo import return_yo 7 | from hola import return_hola 8 | from pow import return_pow 9 | 10 | 11 | def test_imports_worked(): 12 | assert "hi" == return_hi() 13 | assert "hey" == hey.return_hey() 14 | assert "hello" == return_hello() 15 | assert "yo" == return_yo() 16 | assert "hola" == return_hola() 17 | assert "pow" == return_pow() 18 | 19 | 20 | def test_pythonpath_has_correct_order(): 21 | assert sys.path[0] == os.path.join(os.getcwd()) 22 | assert sys.path[1] == os.path.join(os.getcwd(), "test_path/apps") 23 | assert sys.path[2] == os.path.join(os.getcwd(), "test_path/libs") 24 | assert sys.path[-3] == os.path.join(os.getcwd(), "test_path/sitedir1") 25 | assert sys.path[-2] == os.path.join(os.getcwd(), "test_path/sitedir2") 26 | assert sys.path[-1] == os.path.join(os.getcwd(), "test_path/sitedir3") 27 | --------------------------------------------------------------------------------