billions-keyboard-33102
01/11/2023, 11:36 AMmain.py
shim to call pytest.main()
on the tests within the pex. Thank you very much in advance for any guidance on this topic!enough-analyst-54434
01/12/2023, 4:18 PMjsirois@Gill-Windows:/tmp/JakeStacey $ cat src/foo.py
SPAM = 42
jsirois@Gill-Windows:/tmp/JakeStacey $ cat tests/foo_test.py
import foo
def test_foo() -> None:
assert 42 == foo.SPAM
jsirois@Gill-Windows:/tmp/JakeStacey $ pex -D src/ -D tests/ pytest -c pytest --inject-args="--pyargs foo_test -vvs" -o self_contained_test_machine.pex
jsirois@Gill-Windows:/tmp/JakeStacey $ ./self_contained_test_machine.pex
============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.10.6, pytest-7.2.0, pluggy-1.0.0 -- /usr/bin/python3.10
cachedir: .pytest_cache
rootdir: /tmp/JakeStacey
collected 1 item
::test_foo <- ../../home/jsirois/.pex/unzipped_pexes/6a2eed1970bba27bb436991fbe4e7c742865da9e/foo_test.py PASSED
=============================================================================================== 1 passed in 0.00s ================================================================================================
There the key bits are:
1. Your sources and tests are added with -D
2. The executable is pytest (pytest -c pytest
is the pytest requirement with no specifier and then the pytest
console script entrypoint).
3. We seal in some command line args to pass to pytest, namely --pyargs ...
which has pytest discover tests not by file or directory but by package / module name.billions-keyboard-33102
01/13/2023, 11:59 AMbillions-keyboard-33102
01/16/2023, 12:27 PM--inject-args
on the pex_binary
target.enough-analyst-54434
01/16/2023, 12:44 PMbillions-keyboard-33102
01/16/2023, 1:38 PM