pytest

Docker runner pytest does not collect testcases

痞子三分冷 提交于 2019-12-24 12:05:17
问题 I am successfully put ssh-key to docker runner and it can git clone to do dependencies installation. If I use ordinary build-in python manage.py test it works fine. But I am now working with pytest . I can run pytest on ly command line and got results normal. $ pytest ===================================================================================== test session starts ===================================================================================== platform darwin -- Python 3.6.4,

reset_sequence in pytest-django

喜欢而已 提交于 2019-12-24 10:49:50
问题 I have posted my question to the pytest-django. But it seems non-active at least 2 weeks. I decided to ask my question here. In my test I want to use reset_sequence=True. How to do that in pytest-django ? 来源: https://stackoverflow.com/questions/47904245/reset-sequence-in-pytest-django

How to run script as pytest test

大城市里の小女人 提交于 2019-12-24 09:59:50
问题 Suppose I have a test expressed as a simple script with assert -statements (see background for why), e.g import foo assert foo(3) == 4 How would I include this script in my pytest test suite -- in a nice way? I have tried two working but less-than-nice approaches: One approach is to name the script like a test, but this makes the whole pytest discovery fail when the test fails. My current approach is to import the script from within a test function: def test_notebooks(): notebook_folder =

Generate csv file report with pytest

江枫思渺然 提交于 2019-12-24 08:47:05
问题 Is it possible somehow generate the test execution report in csv file? I use python, selenium, pytest. Any advise would be appreciated! 回答1: You can use pytest's plugin API to do so - see e.g. pytest-json for something similar. 回答2: I wrote a pytest-csv plugin, hope this helps. 回答3: I have been using pytest-excel to generate xls file report. Usage: pip install pytest-excel pytest --excelreport=report.xls It will generate report.xls excel file. 来源: https://stackoverflow.com/questions/43480615

I can not run Django Python pytest under PyCharm

大憨熊 提交于 2019-12-24 08:23:13
问题 $ pytest portal/ =============================================== test session starts =============================================== platform darwin -- Python 3.6.0, pytest-3.0.6, py-1.4.32, pluggy-0.4.0 Django settings: config.settings.local (from ini file) rootdir: /Users/el/Code/siam-sbrand/portal, inifile: pytest.ini plugins: django-3.1.2 collected 87 items portal/apps/commons/tests.py ...... portal/apps/price_list_excel_files/tests.py ssssssssssss portal/apps/price_lists/tests.py s....

How to run pytest with a specified test directory on a file that uses argparse?

感情迁移 提交于 2019-12-24 08:05:04
问题 I am writing unit tests for a Python library using pytest I need to specify a directory for test files to avoid automatic test file discovery, because there is a large sub-directory structure, including many files in the library containing "_test" or "test_" in the name but are not intended for pytest Some files in the library use argparse for specifying command-line options The problem is that specifying the directory for pytest as a command-line argument seems to interfere with using

Importing a module does not run the code inside it when running a few unittest files using pytest

半世苍凉 提交于 2019-12-24 07:58:23
问题 I have a few files with tests and an imported file: # test1.py print("running test1.py") import unittest import imported class MyTest1(unittest.TestCase): def test_method1(self): assert "love" == "".join(["lo", "ve"]) def test_fail1(self): assert True, "I failed!" and # test2.py print("running test2.py") import unittest import imported class MyTest2(unittest.TestCase): def test_ok2(self): self.assertEqual(True, 2==2, "I will not appear!") def test_fail2(self): self.assertFalse(False, "Doh!")

Checking the exit code of a CLI in a test

时光总嘲笑我的痴心妄想 提交于 2019-12-24 07:45:40
问题 I am writing automated tests for a command line tool. Essentially, I want to invoke the CLI with various options and test the exit code and/or output. My test looks like this: from mymodule.cli_tool import main def test_args(capfd): with pytest.raises(SystemExit) as e: main(args=['--junk_option']) # check the exit code to make sure it is non-zero ??? How do I check the exit code? 回答1: You need to check value.code , like this: assert e.value.code != 0 来源: https://stackoverflow.com/questions

Mocking a Standard Library function with and without pytest-mock

試著忘記壹切 提交于 2019-12-24 07:41:14
问题 For testing purposes I would like to mock shutil.which (Python 3.5.1), which is called inside a simplified method find_foo() def _find_foo(self) -> Path: foo_exe = which('foo', path=None) if foo_exe: return Path(foo_exe) else: return None I'm using pytest for implementing my test cases. Because of that I also would like to use the pytest extension pytest-mock. In the following I pasted an example testcase using pytest + pytest-mock: def test_find_foo(mocker): mocker.patch('shutil.which',

pytest - Suppress DeprecationWarning from specific 3rd party modules

风流意气都作罢 提交于 2019-12-24 05:22:45
问题 When I run pytest I'm getting some deprecation warnings from a 3rd party library. I'd like to be informed about any deprecation warnings in my own code, but not in a vendored copy of a library bundled with another 3rd-party library. This answer was helpful in getting me partway there. If I run pytest like this: $ pytest ./tests/ I get: $ pytest ./tests/ ============================= test session starts ============================== platform linux -- Python 3.7.4, pytest-5.2.1, py-1.8.0,