File: test_tracker.py

package info (click to toggle)
python-memray 1.17.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,396 kB
  • sloc: python: 28,451; ansic: 16,507; sh: 10,586; cpp: 8,494; javascript: 1,474; makefile: 822; awk: 12
file content (33 lines) | stat: -rw-r--r-- 756 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from pathlib import Path

import pytest

from memray import Tracker


def test_two_trackers_cannot_be_active_at_the_same_time(tmpdir):
    # GIVEN
    output = Path(tmpdir) / "test.bin"
    output2 = Path(tmpdir) / "test2.bin"

    # WHEN
    with Tracker(output):
        # THEN
        with pytest.raises(RuntimeError):
            with Tracker(output2):
                pass


def test_the_same_tracker_cannot_be_activated_twice(tmpdir):
    # GIVEN
    output = Path(tmpdir) / "test.bin"

    # WHEN
    tracker = Tracker(output)
    with tracker:
        # Remove the file so we are not stopped by the file existence check
        output.unlink()
        # THEN
        with pytest.raises(RuntimeError):
            with tracker:
                pass