You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-4Lines changed: 20 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,15 +7,16 @@
7
7
8
8
pytest-inline is a [pytest](<http://pytest.org>) plugin for writing inline tests.
9
9
10
-
Inline testing is a new granularity of testing that make it easier to check individual program statements. An inline test is a statement that allows to provide arbitrary inputs and test oracles for checking the immediately preceding statement that is not an inline test.
10
+
Inline testing is a new granularity of testing that make it easier to check individual program statements. An inline test is a statement that allows to provide arbitrary inputs and test oracles for checking the immediately preceding statement that is not an inline test. Unlike unit tests that are usually placed in separate `test_*.py` files, inline tests are written together with the actual production code (and thus are easier to maintain).
11
11
12
12
## Table of contents
13
13
14
14
1.[Example](#Example)
15
15
2.[Install](#Install)
16
16
3.[Use](#Use)
17
17
4.[API](#API)
18
-
5.[Citation](#Citation)
18
+
5.[Performance](#Performance)
19
+
6.[Citation](#Citation)
19
20
20
21
## Example
21
22
The regular expression (Line 5) in this code snippet checks if variable name matches a regex for a pattern that ends in a colon and has at least one digit
@@ -42,7 +43,7 @@ Use ``pip install pytest-inline`` to install this plugin.
42
43
43
44
## Use
44
45
45
-
Use ``pytest .`` to run all inline tests in working directory.
46
+
Use ``pytest .`` to run all inline tests in working directory.
46
47
47
48
Use ``pytest {filename}`` to run all inline tests in a Python file.
48
49
@@ -123,7 +124,22 @@ Use ``pytest {filename}`` to run all inline tests in a Python file.
123
124
Only one test oracle can be specified for a given inline test call.
124
125
125
126
126
-
# Citation
127
+
## Performance
128
+
129
+
Inline tests are generally fast to run, as each inline test only checks one statement. Note that inline tests behave as empty function calls when not running tests, and the overhead of having them in production code is negligible.
130
+
131
+
We have evaluated the performance of pytest-inline on a [dataset](https://github.com/EngineeringSoftware/inlinetest/tree/main/data/examples/python) of 87 inline tests we wrote for80 statements in50 examples from31open-source projects. The main findings are summarized below, and please see [our paper][paper-url] for more details. We performed 3 experiments:
132
+
133
+
1. Running inline tests in standalone mode. Each inline test took 0.147s on average. Most time is spent on startup and parsing the file, which can be aromatized if there are more inline tests per file. As such, we also duplicated the inline tests for10, 100, 1000 times, and the average time per inline test dropped to 0.015s, 0.002s, 0.001s.
134
+
135
+
2. Running inline tests together with unit tests. The average overhead compared to running only the unit tests was only 0.007x. Even when duplicating the inline tests for1000 times (such that the total number of inline tests match the total number of unit tests), the average overhead was only 0.088x.
136
+
137
+
3. Running inline tests together with unit tests, but disable pytest-inline. This is to simulate the cost of having inline tests in production code. The overhead was negligible: the number we got when not duplicating inline tests was -0.001x (due to noise), and only raised to 0.019x when duplicating the inline tests for1000 times.
138
+
139
+
All APIs for inline testing behave as empty function calls in non-testing mode by always returning a dummy object, for example, check\_eq is defined as: `def check_eq(self, ...): return self`. This usually incurs negligible overhead as we have observed in our experiments, but note that the cost is paid each time an inline test is encountered during execution, so it may add up if the inline test is in a part of code that will be executed many times (e.g., a loop).
0 commit comments