pytest

VSCode pytest test discovery fails

别说谁变了你拦得住时间么 提交于 2020-06-22 11:11:06
问题 Pytest test discovery is failing. The UI states: Test discovery error, please check the configuration settings for the tests The output window states: Test Discovery failed: Error: Traceback (most recent call last): File "C:\Users\mikep\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\testing_tools\run_adapter.py", line 16, in <module> main(tool, cmd, subargs, toolargs) File "C:\Users\mikep\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\testing_tools\adapter\__main__

Pytest Testrail Module - Post Test Results for Test Runs

我的未来我决定 提交于 2020-06-18 13:41:52
问题 I am trying to use the pytest testrail module and started with this demo script: import pytest from pytest_testrail.plugin import testrail @testrail('C165') def test_run(): print "T165:pass" It does create a test run but does not post any results to the corresponding test cases. 回答1: Try adding an assertion as that is what the pytest hook is looking for: import pytest from pytest_testrail.plugin import testrail @testrail('C165') def test_run(): assert False 回答2: Here is add_result function.

Mock authentication decorator in unittesting

微笑、不失礼 提交于 2020-06-14 05:25:10
问题 I wanted to mock validate_token decorator while writing unit test for one of view #views.py from third_part.module import vaidate_token from setting import config class myViews: @validate_token([config['issuer'], config['secret_key']]) def get_data(): #Do stuff return json.loads(data) Here validate_token is a thirtd_party module to authorize request and the token is issued by third party so I don't want execute validate_token decorator for my tests below are my sample test code. test_views.py

Accessing fixtures (e.g., capsys) from a parametrized test

我与影子孤独终老i 提交于 2020-05-30 09:39:37
问题 I'm having trouble accessing fixtures (in this case, capsys) from within a parametrized test. Currently I'm using a dummy fixture to make this work: import pytest @pytest.fixture def params(request): from collections import namedtuple return namedtuple('Params', 'input output')(*request.param) @pytest.mark.parametrize('params', [ ('a', '1a\n'), ('b', '1b\n'), ], indirect=True) def test_output(capsys, params): print('1' + params.input) out, err = capsys.readouterr() assert out == params.output

Error after installation of allure pytest adaptor

时光怂恿深爱的人放手 提交于 2020-05-30 06:39:08
问题 I am trying to configure Allure (2.6.0) with Pytest (3.6xx) on a Windows 8 box. I am able to run pytest and generate jUnit xml report file which later I can pass to allure (allure server jUnitXmlFile.xml) and it works fine. What I need is the additional functionality that Allure provides (metadata,attachments, etc), so I downloaded pytest-allure-adaptor . So I have the following packages installed in my venv: allure-pytest==2.4.1 allure-python-commons==2.4.1 pytest-allure-adaptor==1.7.10 ...

How do I run python's trace with pytest?

不想你离开。 提交于 2020-05-29 09:36:21
问题 I am trying to run a trace on a program that is executed with pytest. I am trying the command python3 -m trace -t pytest test_one.py but it is giving me Cannot run file 'pytest' because: [Errno 2] No such file or directory: 'pytest' as I am assuming trace.py is expecting a file. I saw this similar question but I'm a bit struggling to understand what is supposed to mean - is it supposed to be the executable file for pytest itself (I actually don't see where that is on my computer, I found a

Pytest - error vs fail

走远了吗. 提交于 2020-05-26 10:37:14
问题 Im migrating from PyUnit to Pytest, and I found, that Pytest, unlike PyUnit, does not distinguish fails and errors in test report in quick report while running tests (where dots are printed). How to teach Pytest do do it? UPDATE Seems like it is valid only for PyUnit tests executed with Pytest, thanks to flub for the clue. Code: import unittest class TestErrorFail(unittest.TestCase): def test_error(self): raise Exception('oops') def test_fail(self): self.assertTrue(False) Output: ============

How to keep Unit tests and Integrations tests separate in pytest

泪湿孤枕 提交于 2020-05-26 10:32:08
问题 According to Wikipedia and various articles it is best practice to divide tests into Unit tests (run first) and Integration tests (run second), where Unit tests are typically very fast and should be run with every build in a CI environment, however Integration tests take longer to run and should be more of a daily run. Is there a way to divide these in pytest? Most projects don't seem to have multiple test folders, so is there a way to make sure I only run Unit, Integration or both according

How to keep Unit tests and Integrations tests separate in pytest

。_饼干妹妹 提交于 2020-05-26 10:31:20
问题 According to Wikipedia and various articles it is best practice to divide tests into Unit tests (run first) and Integration tests (run second), where Unit tests are typically very fast and should be run with every build in a CI environment, however Integration tests take longer to run and should be more of a daily run. Is there a way to divide these in pytest? Most projects don't seem to have multiple test folders, so is there a way to make sure I only run Unit, Integration or both according

Using pytest where test in subfolder

北城余情 提交于 2020-05-14 15:35:28
问题 I'm using python pytest to run my unit tests. My project folders are: Main - contains data file: A.txt Main\Tests - the folder from which I run pytest Main\Tests\A_test - folder that contains a test file The test in A_test folder uses the file A.txt (that is in Main folder). My problem is that when I run py.test the test fails because it can't find A.txt . I found out that it is because pytest uses the path Main\Test when running the test instead of changing the path to Main\Tests\A_test (I'm