File: api.rst

package info (click to toggle)
pytest-testinfra 10.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 676 kB
  • sloc: python: 4,951; makefile: 152; sh: 2
file content (24 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
API
===

.. _connection api:

Connection API
~~~~~~~~~~~~~~

You can use testinfra outside of pytest. You can dynamically get a
`host` instance and call functions or access members of the respective modules::

    >>> import testinfra
    >>> host = testinfra.get_host("paramiko://root@server:2222", sudo=True)
    >>> host.file("/etc/shadow").mode == 0o640
    True

For instance you could make a test to compare two files on two different servers::

    import testinfra

    def test_same_passwd():
        a = testinfra.get_host("ssh://a")
        b = testinfra.get_host("ssh://b")
        assert a.file("/etc/passwd").content == b.file("/etc/passwd").content