bitter-ability-32190
04/05/2022, 8:08 PMskip_tests
• a Pants tag
plus remembering to set the CLI arg?
• A pytest
mark, and an arg in our pytest
config to skip?
• Something I'm missing?hundreds-father-404
04/05/2022, 8:09 PMhundreds-father-404
04/05/2022, 8:10 PMhundreds-father-404
04/05/2022, 8:11 PMhigh-yak-85899
04/05/2022, 8:12 PMmy_test_manual.py
which avoids it being caught by the filters of python_tests
. Then, we had a section like
if __name__ == '__main__':
unittest.main()
and used the pex_binary
that tailor
adds to run the tests.hundreds-father-404
04/05/2022, 8:13 PMhigh-yak-85899
04/05/2022, 8:14 PMbitter-ability-32190
04/05/2022, 8:21 PMbitter-ability-32190
04/05/2022, 8:28 PMpython_test(s)
. Along with the machinery to:
• Run the test if specified exactly
• Run if a flag is given to run manual tests?hundreds-father-404
04/05/2022, 8:28 PMbitter-ability-32190
04/05/2022, 8:29 PMhundreds-father-404
04/05/2022, 8:29 PMbitter-ability-32190
04/05/2022, 8:29 PMbitter-ability-32190
04/05/2022, 8:30 PMmanual
tag is always skipped unless otherwise statedbitter-ability-32190
04/05/2022, 8:32 PM[GLOBAL].tag="-manual"
?bitter-ability-32190
04/05/2022, 8:34 PMtag
filtering. Although I struggle ot think of a pex-BInary
or other target which might be tagged manual
hundreds-father-404
04/05/2022, 8:35 PMbitter-ability-32190
04/05/2022, 8:39 PMpython_tests(
name="tests",
tags=["manual_test"],
)
./pants --tag='-manual_test' test path/to/tests/:
Seems to run the testsbitter-ability-32190
04/05/2022, 8:40 PM./pants --tag='-manual_test' test ::
bitter-ability-32190
04/05/2022, 8:43 PMlist
does do the filtering. Weeeeeirdbitter-ability-32190
04/05/2022, 8:44 PM[DEBUG] Completed: Scheduling: Run Pytest for ...
hundreds-father-404
04/05/2022, 8:46 PMhundreds-father-404
04/05/2022, 8:47 PMhundreds-father-404
04/05/2022, 8:47 PMbitter-ability-32190
04/05/2022, 8:51 PMbitter-ability-32190
04/05/2022, 8:53 PMhundreds-father-404
04/05/2022, 8:54 PMdef test_hacky():
pass
high-yak-85899
04/05/2022, 8:55 PMhundreds-father-404
04/05/2022, 8:55 PMhigh-yak-85899
04/05/2022, 8:56 PMhigh-yak-85899
04/05/2022, 8:56 PMbitter-ability-32190
04/05/2022, 8:57 PMbitter-ability-32190
04/05/2022, 9:01 PMbitter-ability-32190
04/05/2022, 9:01 PMimport pytest
@pytest.mark.skip
def test_nothing():
pass
bitter-ability-32190
04/05/2022, 9:03 PMjoshuacannon@CEPHANDRIUS:~/work/techlabs$ ./pants test --force --output=all path/to/test_foo.py -- -vv
16:01:25.17 [INFO] Completed: Run Pytest - path/to/test_foo.py:tests succeeded.
============================= test session starts ==============================
platform linux -- Python 3.8.12, pytest-6.1.1, py-1.11.0, pluggy-0.13.1 -- /home/joshuacannon/.cache/pants/named_caches/pex_root/venvs/s/cf02046f/venv/bin/python3.8
cachedir: .pytest_cache
rootdir: /tmp/process-executionUMiF6w, configfile: pytest.ini
plugins: profiling-1.7.0, kafka-0.5.0, forked-1.4.0, cov-3.0.0, mock-3.7.0, xdist-2.4.0, timeout-2.1.0, mockito-0.0.4
collecting ... collected 1 item
path/to/test_foo.py::test_nothing SKIPPED [100%]
- generated xml file: /tmp/process-executionUMiF6w/path.to.test_foo.py.tests.xml -
============================== 1 skipped in 0.02s ==============================
✓ path/to/test_foo.py:tests succeeded in 0.24s
bitter-ability-32190
04/05/2022, 9:06 PMbitter-ability-32190
04/05/2022, 9:13 PMbitter-ability-32190
04/05/2022, 9:14 PMbitter-ability-32190
04/05/2022, 9:16 PMbitter-ability-32190
04/05/2022, 9:33 PMGood point, will add matching cases hopefully by the end of the week
high-yak-85899
04/05/2022, 9:38 PMbitter-ability-32190
04/05/2022, 9:40 PMhigh-yak-85899
04/05/2022, 9:43 PMpytest.mark.<my_custom_marker>
after specifying custom markers in pytest.ini
. I'm not sure how to configure the skip/deselect behavior. Is that something supported out of the box?high-yak-85899
04/05/2022, 9:45 PMhigh-yak-85899
04/05/2022, 9:45 PMbitter-ability-32190
04/05/2022, 10:08 PMhigh-yak-85899
04/05/2022, 11:01 PMbitter-ability-32190
04/06/2022, 12:21 AMhigh-yak-85899
04/06/2022, 3:17 AMconftest.py
that used pytest_collection_modifyitems
to control what was collected for running. My theory is that since we currently have modules with one marked test in them, pants collects them and then conftest deselects it, and that pants process thinks that no tests were run.rapid-exabyte-76685
04/06/2022, 5:24 AM# pytest.ini
[pytest]
markers =
integration: mark test as integration test
and various test modules that are marked as integration tests, and others that are just unit tests...
# test_some_integration_tests.py
import pytest
pytestmark = pytest.mark.integration
def test_something():
# some integration tests that rely on db resource
# test_some_unit_tests.py
import pytest
# no marks
def test_something_else():
# some unit tests that don't rely on any resources
and getting exit code 5 for both of these attempts to run tests...
./pants test :: -- -m "not integration"
-- i.e. just running "unit" tests
All of the modules that contain pytestmark = pytest.mark.integration
return exit code 5 due to collecting ... collected x item / x deselected / 0 selected
if the unit tests pass, create db and other "expensive" resources in the CI and run integration tests...
./pants test :: -- -m "integration"
-- i.e. just running integration tests
All of the modules that don't contain pytestmark = pytest.mark.integration
also return exit code 5 for the same reason.rapid-exabyte-76685
04/06/2022, 5:27 AMpython_tests
targets with name=test_unit
and name=test_integration
plus tags and explicitly add the test modules to each target, as the solution for moment?
python_tests(
name="tests",
sources=["test_*.py", "!test_an_integration_test.py"]
)
python_tests(
name="integration_tests",
sources=["test_an_integration_test.py"],
tags=["integration_tests"]
)
And then running unit tests/integration tests explicitly becomes...
# run unit tests
./pants -tag=-integration_tests test :: -- -m "not integration"
# run integration tests
./pants -tag=integration_tests test :: -- -m "integration"
rapid-exabyte-76685
04/06/2022, 7:27 AMbitter-ability-32190
04/06/2022, 12:03 PMbitter-ability-32190
04/06/2022, 12:04 PMrapid-exabyte-76685
04/07/2022, 2:52 AM./pants --tag='-integration_test' test ::
doesn't work. And I forget if there is a way to recursively match all test targets with a given name, e.g. ./pants test integration_tests/**::
or somethingbitter-ability-32190
04/08/2022, 3:58 PM--run-manual
is specified:
import pytest
def pytest_configure(config):
config.addinivalue_line("markers", "manual: mark tests which need a person to execute them")
def pytest_addoption(parser):
group = parser.getgroup("manual", "configuration of manual tests")
group.addoption(
"--run-manual",
action="store_true",
default=False,
help="run manual tests",
)
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
if call.excinfo and isinstance(call.excinfo.value, pytest.skip.Exception):
if call.excinfo.value.msg == "manual":
rep.outcome = "manual"
@pytest.hookimpl(tryfirst=True)
def pytest_report_teststatus(report):
if report.outcome == "manual":
return "manual", "M", "MANUAL"
@pytest.hookimpl(tryfirst=True)
def pytest_collection_modifyitems(config, items):
run_manual = config.getoption("run_manual")
for item in items:
if item.get_closest_marker("manual") is not None and not run_manual:
item.add_marker(pytest.mark.skip("manual"))