How to pass environment variables to pytest

Another alternative is to use the pytest-env plugin. It can be configured like so: [pytest] env = HOME=~/tmp D:RUN_ENV=test the D: prefix allows setting a default value, and not override existing variables passed to py.test. Note: you can explicitly run pytest with a custom config, if you only sometimes need to run a specialized environment … Read more

Run code before and after each test in py.test?

py.test fixtures are a technically adequate method to achieve your purpose. You just need to define a fixture like that: @pytest.fixture(autouse=True) def run_around_tests(): # Code that will run before your test, for example: files_before = # … do something to check the existing files # A test function will be run at this point yield … Read more

How to test single file under pytest

simply run pytest with the path to the file something like pytest tests/test_file.py Use the :: syntax to run a specific test in the test file: pytest test_mod.py::test_func Here test_func can be a test method or a class (e.g.: pytest test_mod.py::TestClass). For more ways and details, see “Specifying which tests to run” in the docs.

How do I disable a test using pytest?

Pytest has the skip and skipif decorators, similar to the Python unittest module (which uses skip and skipIf), which can be found in the documentation here. Examples from the link can be found here: @pytest.mark.skip(reason=”no way of currently testing this”) def test_the_unknown(): … import sys @pytest.mark.skipif(sys.version_info < (3,3), reason=”requires python3.3″) def test_function(): … The first … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)