Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import inspect 

2import os 

3from pathlib import Path 

4from typing import Optional 

5 

6import pytest 

7 

8 

9def main( 

10 testfile: Optional[Path] = None, 

11 sequence: Optional[Path] = None, 

12 sequence_format: Optional[str] = 'fasta', 

13 tree: Optional[Path] = None, 

14 tree_format: Optional[str] = 'newick', 

15 data: Optional[Path] = None, 

16 data_format: Optional[str] = 'csv', 

17 verbose: bool = False, 

18 report: Optional[Path] = None, 

19 expression: Optional[str] = None, 

20 cores: Optional[str] = None, 

21): 

22 if not testfile: 

23 testfile = Path(os.path.abspath((inspect.stack()[1])[1])) 

24 args = [testfile] 

25 if not verbose: 

26 args.extend(["-ra", "--tb=no", "--no-header"]) 

27 else: 

28 args.extend(["-v"]) 

29 if sequence is not None: 

30 args.extend(["--sequence", sequence]) 

31 args.extend(["--sequence-format", sequence_format]) 

32 if tree is not None: 

33 args.extend(["--tree", tree]) 

34 args.extend(["--tree-format", tree_format]) 

35 if data is not None: 

36 args.extend(["--data", data]) 

37 args.extend(["--data-format", data_format]) 

38 if report: 

39 if not str(report).endswith('.html'): 

40 raise ValueError(f"Report must use .html extension.") 

41 args.extend([f"--html={report}", "--self-contained-html", f"--css={Path(__file__).parent / 'report/logo.css'}"]) 

42 if expression: 

43 # only run tests which match the given substring expression 

44 # see the pytest help 

45 args.extend(["-k", expression]) 

46 if cores: 

47 # parallel with pytest-xdist 

48 args.extend(["-n", cores]) 

49 exit_code = pytest.main(args, plugins=['phytest']) 

50 return exit_code